MaxNestedExpressionDepth
Sets 200 as the maximum number of function calls that can be included in a single expression. (Most commonly encountered when creating deeply nested IfElse expressions.)
If you encounter this limit, do not increase the maximum nested expression depth. Rather, look for ways to rewrite your code to avoided nested expressions (see following options).
Section: Layer
Default: MaxNestedExpressionDepth = 200
*Restart Required (Settings.Startup property)
Writing long "If Else - Else - Else ... " expressions is not efficient and can be avoided. To prevent excessively nested expressions, the property MaxNestedExpressionDepth limits you to 200 function calls (including IfElse) within a single expression. There is no need to test this limit, regardless of the complexity of your application.
Alternatives to nested IfElse structures:
A common task is to build a string based on the current value of a tag (or several tags). For this example, suppose that you need to build a message or address that varies with a tag's current state. A long and inefficient method might be to write:
[SomeTagName] == 0 ? "Message (or) Address 0" : [SomeTagName] == 1 ? "Message (or) Address 1" : [SomeTagName] == 2 ? "Message (or) Address 2" : etc. for 100 or more messages...
There are alternatives:
Option 1
A much easier method is to use a CASE statement in steady state. All statements will execute, but only the result of the statement matching the requested index will be returned.
X = Case([SomeTagName],
{ 0 } "Message (or) Address 0", { 1 } "Message (or) Address 1", { 2 } "Message (or) Address 2", { etc });
Option 2
Another option is somewhat more complicated to create, but has the benefit that the messages are stored in application properties instead of code and therefore can be added to or edited by anyone with the Configuration privilege. It is not necessary to write more code when messages change or new messages are created.
1. Create a set of application properties for each situation:
Situation0 = Message or Address 0 Situation1 = Message or Address 1 Situation2 = Message or Address 2 (etc.)
2. Write an expression that uses the Variable function to concatenate the tag value onto the prefix "Situation" to return the appropriate property value.
Variable(Concat("Situation",[<SomeTagName1>]))
No comparisons or If-Else statements are required. This single line of code can return any message that you have created. For more complicated situations, use Concat to build the appropriate property name or combine several values into one message or address.