Regular Formulas

Regular Formulas are a great way to perform relatively simple actions or complex actions that do not require an entire code block.


IMPORTANT NOTE: Formula Fields are only executed when an object is updated. This could be through an MQTT message, DynamoDB Update, or other related events.



 A great example of a simple action is unit conversion.


Let’s say that a company has a device for temperature regulation.  The device needs to be implemented in Europe but needs to send data to servers in America.   To solve this issue, the company has decided to have device assets for Celsius and Fahrenheit.  The data comes in as Celsius, but you can create an attribute of type Formula that converts Celius to Fahrenheit automatically.


The formula for this use case would look like this:

      



Another common use case is grabbing a data from a referenced object.


Let's you have an object type called "Employee" that has an attribute named "Company" which is a reference to a Company object the Employee works for. The Company object type has a field called "Manager" and because the employee's Manager is constantly changing you want to make sure the Employee always has the most current Manager associated with them.


To use a reference in a formula field you use the syntax ${[reference_json_key]_r.[attribute_from_ref]}


So for the example to get the Manager from the Company you'd do something this.




Variable json references are in snake case.

ThingLogix uses the following formula syntax for all Formulas

  • All expressions are evaluated in Java, all Java expressions are valid
  • Strings are compared by    equals(“string”, “string”)
  • Variables are referenced by placing the key inside braces:   ${key}
  • Variables can be cast as strings by using “${key}”
  • For More Syntax Click Here