Overview
The Set Variables node is useful for temporary fields within a workflow. These fields do not need to be stored permanently against a record so can help keep apps cleaner without the need for unnecessary hidden fields. It also allows for quick and easy changes within the workflow without having to leave.
Set Variables Node
[Var.VariableName] for same App Workflow Action Nodes
In the example above, the variables are represented with the Var.Name format.
- Variable Name: This field is where you specify the name of your variable. It works similarly to a field ID but does not require a label since it's not a visible option in the workspace.
- Expression: Enter the expression for the variable you wish to create here.
- Add Another Variable: This option allows you to add more variables within the same node.
Note: When using the set variable node it will figure out the field type by itself, i.e. If you are adding two number fields together it will make it a number field type and should be referenced as such later on.
Note: These work very similar to normal fields so when in doubt write it like you would for a normal field expression but a Var. before the field name. [FieldID] = [Var.FieldID]
sourceVar('VariableName',defaultvalue) for Trigger Workflow & Other App Action Nodes
When using your variable in a node that makes an external update to another app, i.e. "update app field value" or "update child field value", or a "create record" node, you will need to use a sourcevar('','') function, this also works similar to the Source. function seen elsewhere. There is an example of it being used further down.
Variable = Var.OpenActions
Source Variable = sourcevar('OpenActions','No Actions')
Note: This would be similar to insull('','') where if it can't find a value for the source variable the second set of quotes is what should be entered instead.
Use Case Scenario using Projects & Actions
Consider a scenario where a Set Variables node is used in sending a project update. The sequence works as follows:
- Button Clicked: Initiates the workflow.
-
Set Variables: Determines the number of open actions using an expression. Using the example from earlier,
[Var.OpenActions] = [ToDo] + [InProgress]. -
Filter:
- If
[Var.OpenActions] > 30, the workflow proceeds to send an email notifying managers that actions are backed up and also sends a Teams message. - If
[Var.OpenActions] < 30, an email is sent indicating that the project is healthy.
- If
The total number of actions is dynamically included in the communications using expressions like @Softools.FieldValue("Var.OpenActions") for emails and [Var.OpenActions] for Teams messages thanks to the variable set earlier on.
For more on how to send teams messages please click here
You could also add a create record node that creates an action linked to the project to reduce the number of actions by a certain date. This would need to use the sourcevar('','') function like below.
Use Case
Sending Reminder Emails - Calculating a value to use in filters
The use case here is that we have a process where an Audit should be completed within 2 weeks of being created. Reminder emails are sent to incomplete Audits:
- 3 Days before they are due
- On the due date
- 3 days after it is due
❌ We could set up:
- A scheduled workflow that sets the current date in a field in every record in the App.
- The Field in each App then calculates how many days the Audit has been open
- Another Field then calculates a status for how close do due date it is
- A Workflow sends the reminder email when the status for how close to due to changes
✅ By using a dynamic variable for each open audit calculating the days the audit has been open, we can then use this in filters to trigger the appropriate reminder email.
- We set up a scheduled workflow to run each day.
- We then filter the records to open audits as we will only send reminders to audits that are still open.
- We use the Set Variable to define the number of whole days since the Audit was created
[Var.DaysSinceCreated] = round(dateDiff([AuditDateCreated], dateNow()), 0)- We can then set up three filter nodes off the back of this to continue the workflow run if the days since creation meets a reminder email condition
3 days before due: [Var.DaysSinceCreated] = 11
on the date due: [Var.DaysSinceCreated] = 14
3 days after due: [Var.DaysSinceCreated] = 17- On the back of the filter condition being met we add the Send Email workflow
⭐ There are three reason that a Variable works so well here:
- One is to reduce unnecessary processing on the Audit Records. We don't need to update the Audit Records at all. As the variable calculates the days open audits have been open, we can add the subsequent actions with the temporary value while the workflow runs. (We may add minimal record processing such as setting an overdue flag if we choose to).
- Rather than adding complex filters based on date criteria (date and Boolean can get tricky or not fully possible directly in the filter node), we create a temporary number value which is far easier and fully flexible to build the reminder filter criteria from.
- The variable is for days since creation is calculated once and then referenced in multiple filters. This saves repeated calculation making it efficient, easier to maintain and clearer to follow.
Variables in AI Nodes
AI Nodes have a variable built into them to capture the response of the calls that they make.
These follow the same rule that referencing the variable value is via [Var.VariableName] unless it is in a Record Create, Update Child Field Value node or nodes in subsequent started by workflow run in which case it will use the sourceVar('VariableName',default value) reference to call the varibale value.
For more on this see the Workflow AI Nodes support article.
Comments
0 comments
Please sign in to leave a comment.