Expression Rule Syntax

This section identifies the syntax requirements for creating Expression Rules. You create Expression Rules by defining expressions in the If, Then, and Else fields of the Create expression rules page. You add the variables, functions, and actions, and operators, parenthesis, and so forth to the If, Then, Else fields.

 

For example, for a Data trigger (message), you may define the following Expression Rule:


If
: DataItem.Temp.value > 82 && DataItem.AC.value == 1.0

Then: CreateAlarm("High Temp", "AC is on, temperature = " +str(DataItem.Temp.value), 250, "STARTED")

Else: SendDataItem("MachineTemp", 100)

 

In the above example, Temp and AC are data items for the model. Refer to DataItem Namespace for information about specifying data items in an expression.

If Temp is greater than 82 and AC is equal to 1, the Platform runs the CreateAlarm() action. For this action, the Platform creates a new alarm, named "High Temp", and gives it the following attributes:
 

§         a description of "AC Is on, temperature = " + str(DataItem.Temp.value) (here, the server replaces str(DataItem.Temp.value with the actual value of Temp)

§         a severity of 250

§         a state of STARTED.

Note: The data item, Temp, must be converted to a string value before it can be used in a string. Refer to Basic and statistical functions for expression rules for information about using non-string values in a string.

If the If expression is false, the Platform runs the SendDataItem() action. For this action, the Platform sends the value 100 to the data item, MachineTemp.

This expression rule uses various operators to create the logic, including > (greater than), && (Boolean AND), and == (is equal to). For a complete list of operators you can use, refer to the topic, Supported Operators.

Also, string values must be set off by double quotes. See the Syntax guidelines for Expression Rules topic for complete information.

Validating your expression rule

You can select to validate your expression rule before it is complete or upon completion. When you click the Validate button, the Platform reads the information entered in the expression fields to make sure the syntax of the functions is correct and that the If expression evaluates to true or false (Boolean value). If it detects any syntax errors, the Platform highlights the fields containing the errors in red. If you mouse over the field, the Platform displays the possible errors in a balloon. You need to fix any errors before the Platform allows you to save the expression rule.

The Platform does NOT ensure that any values defined in the functions as parameters actually exist in the Platform. Additionally, the Platform cannot determine that the spelling of any user-defined values is correct. If the expression does not execute during runtime, you should make sure the values defined in the functions are entered correctly.

When ready, click Save to save the expression rule to the Platform. The Platform validates its syntax again and, if errors still exist, the fields are highlighted in red. Again, you need to fix any errors before the Platform lets you save the expression rule. If it does not detect any errors, the Platform saves the expression rule.