Intro to Expressions
Logical expressions are like the building blocks for setting up your automatic tasks in Symphona. They help you do things like adding up numbers, saving information, and deciding which steps to take next based on certain conditions.
Getting to know how these expressions work is key to really taking advantage of what Symphona can do, making your automated workflows smarter and more tailored to your needs. It's like learning the rules of a game that allows you to direct exactly how your tasks are carried out.
But don’t worry – it’s easy to get started with logical expressions, and the more expressions you write, the better you’ll get at making them.
In this tutorial, we’ll go over:
- What logical expressions are
- How to use logical and arithmetic operators to create expressions
- How to use parameters within expressions
- How you can use expressions within some common Symphona steps
Let’s dive in!
What are logical expressions?
A logical expression is a statement that can be TRUE or FALSE.
For example, x < y is a logical expression. It can either be TRUE or FALSE depending upon what values we give x and y.
Value of x | Value of y | Value of x < y |
4 | 6 | TRUE |
4 | 2 | FALSE |
4 | 4 | FALSE (4 is equal to 4, not less than 4) |
When you’re creating workflows in Symphona, you’ll need to use logical expressions to:
- Calculate a value that Symphona can store in a parameter
- Create conditional branches (if x < y, do branch 1. Otherwise, execute branch 2.)
Fortunately, logical expressions aren’t difficult to create. They can be as simple or as complicated as you need them to be.
Logical Operators
Logical operators are used to evaluate an expression to determine if it is TRUE (1 in binary) or FALSE (0 in binary).
We saw before than < or less than, is a logical operator that checks if the argument to its left is less than the argument to its right.
Another example is ==. It checks the equality of two arguments. 5 == 4, or 5 is equal to 4, will return FALSE. If we instead wrote 5 > 4, or 5 is greater than 4, that would return TRUE.
Below is a table of the logical operators Symphona supports.
Operator | Meaning |
== | equal |
!= | not equal |
&& | AND (all arguments connected by && must be TRUE for the expression to return TRUE) |
|| | OR (all arguments connected by || must be FALSE for the expression to return FALSE) |
> | greater than |
< | less than |
null | undefined |
() | Brackets |
Examples
Here are some examples of how these operators work. Note how you can combine logical operators to create expressions that will help you design and execute your workflow.
Description | Expression |
var1 is not equal to var2 | var1 != var2 |
var1 is not equal to var2 and var3 | var1 != (var2 && var3) |
var1 is equal to var2 or var3 | var1 == (var2 || var3) |
You can also use logical operators alongside arithmetic operators for expressions that work with numbers (+ , -, *, and / , for addition, subtraction, multiplication, and division respectively).
Description | Expression |
var1 is greater than the sum of var2 and var3 | var1 > var2 + var3 |
The sum of var1 and var2 is less than var3 | var1 + var2 < var3 |
The product of var1 and var2, all divided by var3, equals 5. | (var1 * var2) / var3 == 5 |
Note: for those who have coded before, Symphona expressions follow the same syntax as JSON dot notation. If you’re familiar with JavaScript, writing expressions in Symphona will be the same (except functions, which are currently not supported).
Using Parameters in Expressions
Any parameters you define within a workflow can be used in expressions. If you’re writing in an expression field, typing in @ will pull up a menu of available parameters.
If you need a refresher on what parameters are or how to create and use them in Symphona, you can check out our tutorial on parameters here.
Using Expressions
Many steps in Symphona make use of expressions. This tutorial will highlight two: Evaluate Expression and Conditional Branch.
Evaluate Expression
Evaluate Expression will take in an expression, handle exceptions if the result is FALSE, and otherwise store the output in a parameter.
For example, this expression will evaluate the sum of inventoryCount and furnitureCount and store that value in a new parameter, totalCount.
Conditional Branch
Conditional Branch steps allow for multiple paths within your process. Symphona will execute a particular path if an expression evaluates to TRUE. With that in mind, make sure that when you’re setting up your expressions that only one can be TRUE at any time.
In this example, the branch step checks what is greater: inventoryCount or furnitureCount. If inventoryCount is greater, it will trigger an email to be sent. If furnitureCount is greater, then it will create a fallout ticket and end the process.
For more on how to create conditional flows, you can check out our tutorial on that here.
That’s everything you need to get started writing expressions in Symphona!