Workflow variables contain values that can be used in the context of a session.
Variables can generally be used in verification nodes or in the content of a message.
Define the variable
Open the workflow home page and click Edit in the Settings card.
In the Variables section, you can view the available variables and add new ones.
The available value types are:
- integer: example, loyalty program points at the beginning of the flow
- string: for text values;
- date and time: example, the date of issue of a voucher or the expiration date of a subscription;
- Yes/No: for example, the contact is subscribed to a service;
- list of values;
- decimal number: for example, the amount of the last donation made.
The name describes the variable label, while the ID corresponds to the identifier used in the code and expressions - therefore, it cannot contain spaces or special characters.
Assign a value
Within the workflow designer, use the Update variable node to assign a value.
The value is often assigned at the beginning of the session, in order to preserve the initial value of a field, or to calculate a value that will be used later throughout the workflow session.
In this example, a promotion end variable is declared as 30 days after the contact's birthday. This date can be used both in a condition check node and in the content of a message.
Enter the expression to calculate the value of the variable:
- to use the value of a contact field: contact.values.NAME;
- to use the value of a workflow variable: workflow.values.NOMEVAR;
- to assign a value to a number, use a period as the decimal separator (not a comma);
- to assign a value to a True/False type, only the following are accepted: true/false, yes/no;
- for single or multiple choice types, if you specify a value that does not exist, the variable will not be evaluated;
- to assign a text value to a variable, you must enclose it in quotation marks: ‘color’.
Example expression: to add 1 to the value of a numeric variable, use workflow.values.VARIABLENAME + 1.
Check which functions you can use to manipulate numbers, dates, or text strings. In the example, fn.today() expresses today's date.
Use the variable
Use the variable content in workflow messages.
The placeholder to be inserted in the text is of the type [workflow:VariableID]
There is no need to remember the nomenclature; use the icon to insert a placeholder and, instead of the contact field, select Workflow variables from the first drop-down menu.
Testing variable content
To perform a test, start a workflow test session.
Open the details of the current session and access the Variables section.
You will find the variables assigned with their current values.