How to Use the Expression Editor in the App Editor
  • 05 Aug 2023
  • 6 Minutes to read
  • Contributors

How to Use the Expression Editor in the App Editor


Article Summary

Here's how to use the Expression Editor to build more powerful apps.

Purpose

Expressions are a powerful tool for modifying text and numerical values within Triggers. You can modify:

  1. Table Records: Records you have loaded into the app in a previous statement
  2. App Info: Default app fields, like User, Station, and Time Elapsed on Step
  3. Variables: The value of variables within that run of the app at the time that the Trigger fires.

Common use cases include...

  1. Converting text into a Number
  2. Converting a number into text
  3. Modifying the output of a barcode scanner
  4. Combining static text with Variable values

If you are planning on using variable values in a text string, you should use the Expression Editor rather than "Static Value" "text".

Accessing the Expression Editor

The Expression Editor is available as an initial choice within "If" statements, and it is available as an option within Actions in "Then" statements.

For "If" statements, you can write logic based on an Expression.

In "Then" statements, it is available within actions like "Data Manipulation" "Store".

Writing an Expression

To use an Expression, you must insert a:

  • Variable
  • Table Record Field
  • App field
  • Static Value

into the parentheses included in the expression.

In the example below, the value from the variable called "barcode" is added to a TEXTTONUMBER() function.

  • "Data Manipulation" "Store" data: "Expression" "TEXTTONUMBER(Variable.barcode)"

If the expression is valid, you will get a "Valid Expression" message at the bottom of the Editor.

If you plan on using a variable value in a text string, you must use quotes (") to surround the text string, and plus symbols (+) to join the Variable value with the string.

Example:

Text: 'My work order ID is: ' + @Table Record.Test WO Record.ID  + 'and my badge ID is: ' + @App Info.Logged-in User.Badge Id

Common Use Cases Explained

Converting Text to a Number

To convert text to a number, you must first decide if you want the number to be a float (with decimal places) or an Integer.

Let's imagine that you want to convert text to a float. Here's how you might do that:

  • "Data Manipulation" "Store" data: "Expression" "PARSEFLOAT("123.14")

This will convert "123.14" to 123.14.

Converting Number to Text

Since Tables require a text value for a unique ID, you will need to convert any numbers to text.

To do this, simply add an a set of quotes after the number using the "+" operator.

NumberString

  • "Data Manipulation" "Store" data: "Expression"
  • 123.456 + ""
  • Note - This must be two double quotes ("") or two single ('') quotes after the "+"

You can think of this as a "TOTEXT" Expression.

Modifying Barcode Scanner Output

First, you must figure out the format of the barcode scanner output. Let's assume that it is text, and you want to convert it to a number.

To do that, you must use TEXTTONUMBER() on the scanner output. It looks like this:

  • "Data Manipulation" "Store" data: "Expression"
  • TEXTTONUMBER(Device Output.data)
  • location: "work_order"

Creating a Comma-Separated List of Values

You can combine multiple strings or numbers into one string, with each value separated by a comma. You can add on to an existing field in a table, or simply combine multiple Variables or Static Values.

Here's how to combine the values stored in 2 variables into one text value:

  • "Data Manipulation" "Store" data: "Expression"
  • Variable.Defect Report-Defect Type + "," + Variable. Defect Report-Defect Description

Adding New Lines within Text

Let's say that you want to share the results of an app completion with a supervisor. You can do this by sending an email via a Trigger. You can add new lines to the email text by pressing SHIFT+ ENTER while typing within closed quotes in the Expression Editor. It will look like this:

Expression:
'This is line1
' + 'This is line2
' + 'This is line3'

Further Reading


Did you find what you were looking for?

You can also head to community.tulip.co to post your question or see if others have faced a similar question!


Was this article helpful?