<< Click to Display Table of Contents >>
Expressions |
Some properties of controls, such as Title and Subtitle, can be defined using an expression whose result varies according to the value of a Tag. To insert an expression, the value of the property must start with an equal (=) symbol.
Expressions are codes in JavaScript language that must result in a value. The available functions for expressions are listed on the next table.
Available functions for expressions
Function |
Parameter |
Result |
---|---|---|
ValueOf(TagName) |
A String with the path to a Tag |
Value of a Tag. Its data type can be String, number, Boolean, or null |
TimestampOf(TagName) |
A String with the path to a Tag |
Date, in milliseconds since January 1st, 1970, of the value of a Tag. Equivalent to the return of the getTime function of Date data type in JavaScript language. Data type is number |
QualityOf(TagName) |
A String with the path to a Tag |
Quality of the value of a Tag, in OPC UA format. Data type can be String, number, Boolean, or null |
IsQualityGood(TagName) |
A String with the path to a Tag |
Indicates whether the quality of a Tag is good or not. Data type is Boolean |
In the next example, the Title property of a Display shows the text "Cold Water" if the value of Tag demo:TagInternal1 is less than or equal to 20 °C and shows the text "Hot Water" if the value of the Tag is greater than 20 °C.
=ValueOf("demo:TagInternal1") <= 20 ? "Cold Water" : "Hot Water"
In addition to texts, the color of a control can also be changed according to the value of a Tag. In this case, the value of the Color property can contain a hexadecimal code, according to the next example.
=ValueOf("demo:TagInternal1") <= 20 ? "#0000ff" : "#ff0000"
Or it can contain the name of a color, according to the next example.
=ValueOf("demo:TagInternal1") <= 20 ? "blue" : "red"
To view and manipulate dates, users can use the Date class from JavaScript language with the TimestampOf function, according to the next example.
=new Date(TimestampOf("demo:TagInternal1"))
This way, users can use any method from the Date class. Another possibility is using the IsQualityGood and ValueOf functions to only show values if the Tag contains a value with good quality, according to the next example.
=IsQualityGood("demo:TagInternal1") ? ValueOf("demo:TagInternal1") : "Bad Quality"
For more information, please check topics about expressions and operators and about the Color data type on MDN Web Docs.