Set Flow Variables flow logic

  • Release version: Xanadu
  • Updated August 1, 2024
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    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. These variables store flow data as data pills, which can be accessed and used throughout the flow. This logic does not create variables but updates their values using strings, scripts, or references to other data pills.

    Show full answer Show less

    Key Features

    • Variable Assignment: Select from existing flow variables and assign values via direct input, scripts, or data pills from earlier in the flow.
    • Order Dependency: When referencing other variables or data pills, maintain assignment order to avoid null values, as values are set sequentially from top to bottom.
    • Script Support: Enables inline scripting for complex value assignments using the script editor, with access to flow and action data through the fddata object.
    • Multiple Assignments: If a variable is assigned multiple times, only the last assigned value is retained.
    • Data Pill Access: Updated flow variables appear as data pills in the Flow Variables section of the Data pane for use in subsequent flow actions.

    Practical Usage

    This flow logic is commonly used to dynamically store and reuse data, such as setting an incident number variable based on a condition (e.g., category equals network). The stored variable can then be referenced later in the flow, for example, to customize email subjects or bodies.

    Assignments can be done directly from data pills or by scripting, giving flexibility to handle more complex scenarios.

    What to Expect

    • Efficient management of flow data through reusable variables.
    • Flexibility to define variable values via scripts or direct data references.
    • Improved flow readability and maintainability by centralizing data assignments.
    • Potential pitfalls if variable assignment order is not maintained, which can result in null values.

    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.

    Important:
    This flow logic sets values for flow variables that have already been created. For instructions on creating flow variables, see Create a flow variable.

    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.

    Use a data pill value to set a flow variable.

    Later in the flow, the Send Email action uses the incident number flow variable as part of the email subject and body.

    Send Email action that uses the Flow Variable incident number in both the subject and body of the email.

    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;

    Use a script to set a flow variable.

    Execution details

    Figure 1. Execution details for set the incident number variable value to a data pill value
    Example execution details of setting a flow variable with a data pill.
    Figure 2. Execution details for set the incident number variable value using a script
    Example execution details of setting a flow variable with a script. Example execution details of setting a flow variable with an inline script.