Set Flow Variables flow logic
Summarize
Summary of Set Flow Variables flow logic
The Set Flow Variables flow logic in ServiceNow allows you to assign values to one or more pre-created flow variables, which are stored as data pills. These variables hold flow data that can be referenced and used throughout your flow. This logic does not produce outputs but updates the values of existing flow variables, enabling dynamic data handling within the flow.
Show less
Key Features
- Variable Assignment: Select variables from a list of those already created in the flow and assign values using strings, scripts, or other data pills from earlier in the flow.
- Order Dependency: When referencing other data pills in variable assignments, maintain the top-to-bottom order to prevent null values, as values are set sequentially.
- Multiple Assignments: If the same variable is assigned multiple times, only the last assigned value is used during flow execution.
- Inline Scripting: Supports scripting for complex assignments, accessed via the script editor, allowing dynamic and conditional value setting based on flow data.
- Data Access: Flow variables appear as data pills in the Flow Variables section of the Data pane, making them easy to use in subsequent actions or conditions within the flow.
Practical Usage Examples
- Assigning from Data Pills: For instance, store an incident record number in a flow variable when an incident meets a condition (e.g., category is network), then use that variable in actions like sending emails.
- Assigning via Script: Use inline scripts to set variable values dynamically, such as retrieving the incident number from the trigger data object (fddata) and returning it for assignment.
What to Expect
By using the Set Flow Variables flow logic, you can efficiently manage and manipulate flow data, enabling more flexible and dynamic workflows. This functionality supports complex flow designs by allowing variable values to be set and updated based on flow conditions and data, which can then be seamlessly referenced throughout the flow for actions, decisions, and notifications.
Assign a value to one or more flow variables, which store flow data as data pills. Access flow variable values by referring to their data pill.
Inputs
| Field | Description |
|---|---|
| Name | Name of the variable. Select from the list of variables available for the flow. |
| Data | Value for the variable. Enter a string value, input a script, or use a data pill. Variable values can reference any data pill from
earlier in the flow, including other variables. If you set variable values by reference to
other data pills, you must maintain the order of the variable assignments. The referenced
value must always come before the variable that uses the referenced value. Changing the
order may produce null values. To assign an empty value, leave this field empty. Note: Flow variable values are set in the order in which they're assigned from top to bottom. If you set the value of the same variable multiple times, the flow only uses the last value set. To enter a script, select the Toggle scripting on for [variable] icon. Enter your script in the script editor. For more information about inline scripting, see Inline scripts. |
Outputs
This flow logic produces no outputs but does change the value of flow variables.
Usage
Flow variables store flow data as data pills of a specific data type. You can access flow variable data pills from the Flow Variables section of the Data pane. To use a flow variable value, select the data pill from the Data pane or the pill picker just as you would any other data pill.
Set the incident number variable value to a flow data pill value
In this example, the flow checks the category of an incident record. If the category is network, a flow variable is used to store the record number.
Later in the flow, the Send Email action uses the incident number flow variable as part of the email subject and body.
Set the incident number variable value using a script
In this example, the flow checks the category of an incident record. If the category is network, a flow variable is used to store the record number. In this example, the flow variable is set from a script rather than a data pill value.
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var incNumber = fd_data.trigger.current.number;
return incNumber;