Product documentation Docs
    • English
    • Deutsch
    • 日本語
    • 한국어
    • Français
  • More Sites
    • Now Community
    • Developer Site
    • Knowledge Base
    • Product Information
    • ServiceNow.com
    • Training
    • Customer Success Center
    • ServiceNow Support Videos
  • Log in

Product documentation

  • Home
How search works:
  • Punctuation and capital letters are ignored
  • Special characters like underscores (_) are removed
  • Known synonyms are applied
  • The most relevant topics (based on weighting and matching to search terms) are listed first in search results
Topics are ranked in search results by how closely they match your search terms
  • A match on the entire phrase you typed
  • A match on part of the phrase you typed
  • A match on ALL of the terms in the phrase you typed
  • A match on ANY of the terms in the phrase you typed

Note: Matches in titles are always highly ranked.

  • Release version
    Table of Contents
    • Now Platform capabilities
Table of Contents
Choose your release version
    Home Paris Now Platform Capabilities Now Platform capabilities Workflow Workflow management Using variables in a workflow

    Using variables in a workflow

    • Save as PDF Selected topic Topic & subtopics All topics in contents
    • Unsubscribe Log in to subscribe to topics and get notified when content changes.
    • Share this page

    Using variables in a workflow

    Within workflow there are several different types of variables that are available.

    Some variables define, describe, or compose the pieces of the workflow (such as workflow activities). Some variables are available specifically to facilitate the execution of a workflow (such as scratchpad variables). Some variables define, describe, or compose the data records being manipulated by the workflow process (for example, the elements of a Glide Record that are defined in a dictionary.xml file describing a record, such as an incident).

    Activity variables

    Activity variables are properties specifically associated with a workflow activity.

    About this task

    These are the inputs that appear on the activity definition when a specific activity is dragged onto the workflow canvas. These variables are properties that define, compose or describe the workflow activity, or the work it is designed to perform.

    Activity variables are declared in a related list within the Workflow Activity Definition.

    To add, view, or modify a variable:

    Procedure

    1. Navigate to Workflow > Activity Definitions.
    2. Select a workflow activity, such as Approval - User.
    3. In the Activity Variables section or tab, add, view, or modify the variables. Activity variables are defined using the same fields as Dictionary records.
      Note: If defining a new activity variable that is dependent on another activity variable, put the prefix "vars." before the name of the parent activity variable. For example, if the child field is dependent on a field named parent, put the value vars.parent in the Dependent field.
      To control the visibility of an activity variable on the workflow canvas after the activity has been dragged to the canvas, use a UI policy on the wf_activity table.
      To access the variables or assign values to these variables within the workflow activity, use the vars variable of the workflow activity.
       activity.vars.variable_name = new_variable_value 

    Workflow input variables

    Workflow variables are external values that are passed into and referenced by a workflow during its execution.

    About this task

    Workflow variables can be declared externally in a script and passed into a main workflow or they can be declared within a main workflow and passed as inputs to a subflow.
    Note: There is a specific kind of input variable for any workflow that is declared against the table Requested Item [sc_request_item]. To understand the use of these variables see Workflow catalog variables.

    Workflow variables are declared in a form available from the Workflow Editor gear menu.

    To add, view, or modify a variable:

    Procedure

    1. Navigate to Workflow > Workflow Editor.
    2. Edit and checkout a workflow.
    3. Select the Workflow Activities menu and select Edit Inputs.
    4. Select an existing variable or click New.

      Note the Column name field. Use this value when accessing the variable from a script.

      Workflow variables do not appear on the workflow canvas, they are only available for view from the Workflow Activity menu.

      The input variables are available to use in scripts. To access an input variable from a script:
      var input  = workflow. variables. variableName //get the workflow variable identified by column name.

    Assigning values to variables from outside of workflow

    After being declared in a workflow, values can be assigned to the variables from where the workflow is kicked off.

    The following example demonstrates how a workflow variable's value can be set in a script include, business rule, or UI action:
     
    //Declare an instance  of workflow.js 
    var wf  = new Workflow ( ) //Get the workflow id 
    var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
    //Start workflow, passing along name : value pair(s) for mapping to variable 
    //where input_var_name is the name of the variable declared in gear menu 
    //and input_var_value is whatever that value should be for this execution of 
    //workflow
    wf. startFlow (wfId , null , "Workflow Name" , {input_var_name : input_var_value } ) ;
    Another example that demonstrates a more readable way of passing multiple variables involves declaring an object, adding the names/values to the object, and passing it:
    //Declare an instance  of workflow.js 
    var wf  = new Workflow ( ) 
    //Get the workflow id 
    var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
    //Start workflow, passing along object containing name/value pairs mapping to inputs expected by the workflow 
    var vars  = { } ;
    vars. input_var_name1 = input_var_value1 ;
    vars. input_var_name2 = input_var_value2 ; 
    // add as many variables as your workflow is expecting, then pass the object
    wf. startFlow (wfId , null , "Workflow Name" , vars ) ;

    Assigning Values for Subflow Inputs from inside of a Main Workflow

    If a workflow that accepts inputs is called from within another workflow, those input values can be set from the workflow canvas within the UI of the workflow activity. Each input variable declared for a subflow will have a text box input area displayed on the activity. Within these text boxes, the variables can be set with any value either from the scratchpad or from within the current record.

    For more information, see Workflows used as subflows.

    Reading the Value of a Workflow Input Variable

    The value of a Workflow input variable is accessible anywhere within the workflow that accepts javascript by dot walking the current workflow object:
    var readValue = workflow.inputs.variable_name;

    Workflow scratchpad variables

    Store and share string-based variables as name-value pairs between workflow activities.

    The scratchpad is global to the instance of the running workflow and as such, is available equally to all activities.

    Declaration

    The scratchpad itself is automatically available to an executing workflow and requires no specific declaration. Variables are declared and stored in the scratchpad simultaneously by referencing it. For example:
    workflow.scratchpad.variableName = variableValue;

    Display

    View activity scratchpad values from the Workflow Activity History Scratchpad [wf_history_scratchpad] table. Workflow Activity History Scratchpad is also an embedded list in Worfklow Activity History records.

    Figure 1. Sample Workflow Activity History Scratchpad records

    Access and Assignment

    Use standard JavaScript object notation to access or assign scratchpad values. For example, use this format to assign a particular scratchpad variable value.
    workflow.scratchpad.variableName = variableValue;
    Use this format to assign a JavaScript variable to a scratchpad variable.
    var myValue = workflow.scratchpad.variableName;

    Current variables

    Current is the database GlideRecord that kicked off the workflow, either by association to the table in the Workflow properties table or by being associated with a catalog item.

    Declaration

    Variables in current are the columns that are defined in the dictionary.xml file that support the database record. There is no way at runtime to add variables to the current record.

    Display

    Variables of a current record are displayed on the Glide Forms and Lists throughout the applications that use them.

    Access and Assignment

    To access the variables or assign values to the variables within the workflow activity, get the value from the current record by referencing the Glide Element.
    var myVarValue = current.getElement(nameOfTheField);
    or
    var myVarValue = current.fieldName;
    or
    current.variableName.setValue( "A Variable Value");

    Tags:

    Feedback
    On this page

    Previous topic

    Next topic

    • Contact Us
    • Careers
    • Terms of Use
    • Privacy Statement
    • Sitemap
    • © ServiceNow. All rights reserved.

    Release version
    Choose your release version

      Using variables in a workflow

      • Save as PDF Selected topic Topic & subtopics All topics in contents
      • Unsubscribe Log in to subscribe to topics and get notified when content changes.
      • Share this page

      Using variables in a workflow

      Within workflow there are several different types of variables that are available.

      Some variables define, describe, or compose the pieces of the workflow (such as workflow activities). Some variables are available specifically to facilitate the execution of a workflow (such as scratchpad variables). Some variables define, describe, or compose the data records being manipulated by the workflow process (for example, the elements of a Glide Record that are defined in a dictionary.xml file describing a record, such as an incident).

      Activity variables

      Activity variables are properties specifically associated with a workflow activity.

      About this task

      These are the inputs that appear on the activity definition when a specific activity is dragged onto the workflow canvas. These variables are properties that define, compose or describe the workflow activity, or the work it is designed to perform.

      Activity variables are declared in a related list within the Workflow Activity Definition.

      To add, view, or modify a variable:

      Procedure

      1. Navigate to Workflow > Activity Definitions.
      2. Select a workflow activity, such as Approval - User.
      3. In the Activity Variables section or tab, add, view, or modify the variables. Activity variables are defined using the same fields as Dictionary records.
        Note: If defining a new activity variable that is dependent on another activity variable, put the prefix "vars." before the name of the parent activity variable. For example, if the child field is dependent on a field named parent, put the value vars.parent in the Dependent field.
        To control the visibility of an activity variable on the workflow canvas after the activity has been dragged to the canvas, use a UI policy on the wf_activity table.
        To access the variables or assign values to these variables within the workflow activity, use the vars variable of the workflow activity.
         activity.vars.variable_name = new_variable_value 

      Workflow input variables

      Workflow variables are external values that are passed into and referenced by a workflow during its execution.

      About this task

      Workflow variables can be declared externally in a script and passed into a main workflow or they can be declared within a main workflow and passed as inputs to a subflow.
      Note: There is a specific kind of input variable for any workflow that is declared against the table Requested Item [sc_request_item]. To understand the use of these variables see Workflow catalog variables.

      Workflow variables are declared in a form available from the Workflow Editor gear menu.

      To add, view, or modify a variable:

      Procedure

      1. Navigate to Workflow > Workflow Editor.
      2. Edit and checkout a workflow.
      3. Select the Workflow Activities menu and select Edit Inputs.
      4. Select an existing variable or click New.

        Note the Column name field. Use this value when accessing the variable from a script.

        Workflow variables do not appear on the workflow canvas, they are only available for view from the Workflow Activity menu.

        The input variables are available to use in scripts. To access an input variable from a script:
        var input  = workflow. variables. variableName //get the workflow variable identified by column name.

      Assigning values to variables from outside of workflow

      After being declared in a workflow, values can be assigned to the variables from where the workflow is kicked off.

      The following example demonstrates how a workflow variable's value can be set in a script include, business rule, or UI action:
       
      //Declare an instance  of workflow.js 
      var wf  = new Workflow ( ) //Get the workflow id 
      var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
      //Start workflow, passing along name : value pair(s) for mapping to variable 
      //where input_var_name is the name of the variable declared in gear menu 
      //and input_var_value is whatever that value should be for this execution of 
      //workflow
      wf. startFlow (wfId , null , "Workflow Name" , {input_var_name : input_var_value } ) ;
      Another example that demonstrates a more readable way of passing multiple variables involves declaring an object, adding the names/values to the object, and passing it:
      //Declare an instance  of workflow.js 
      var wf  = new Workflow ( ) 
      //Get the workflow id 
      var  wfId  = wf. getWorkflowFromName ( "Workflow Name" ) ; 
      //Start workflow, passing along object containing name/value pairs mapping to inputs expected by the workflow 
      var vars  = { } ;
      vars. input_var_name1 = input_var_value1 ;
      vars. input_var_name2 = input_var_value2 ; 
      // add as many variables as your workflow is expecting, then pass the object
      wf. startFlow (wfId , null , "Workflow Name" , vars ) ;

      Assigning Values for Subflow Inputs from inside of a Main Workflow

      If a workflow that accepts inputs is called from within another workflow, those input values can be set from the workflow canvas within the UI of the workflow activity. Each input variable declared for a subflow will have a text box input area displayed on the activity. Within these text boxes, the variables can be set with any value either from the scratchpad or from within the current record.

      For more information, see Workflows used as subflows.

      Reading the Value of a Workflow Input Variable

      The value of a Workflow input variable is accessible anywhere within the workflow that accepts javascript by dot walking the current workflow object:
      var readValue = workflow.inputs.variable_name;

      Workflow scratchpad variables

      Store and share string-based variables as name-value pairs between workflow activities.

      The scratchpad is global to the instance of the running workflow and as such, is available equally to all activities.

      Declaration

      The scratchpad itself is automatically available to an executing workflow and requires no specific declaration. Variables are declared and stored in the scratchpad simultaneously by referencing it. For example:
      workflow.scratchpad.variableName = variableValue;

      Display

      View activity scratchpad values from the Workflow Activity History Scratchpad [wf_history_scratchpad] table. Workflow Activity History Scratchpad is also an embedded list in Worfklow Activity History records.

      Figure 1. Sample Workflow Activity History Scratchpad records

      Access and Assignment

      Use standard JavaScript object notation to access or assign scratchpad values. For example, use this format to assign a particular scratchpad variable value.
      workflow.scratchpad.variableName = variableValue;
      Use this format to assign a JavaScript variable to a scratchpad variable.
      var myValue = workflow.scratchpad.variableName;

      Current variables

      Current is the database GlideRecord that kicked off the workflow, either by association to the table in the Workflow properties table or by being associated with a catalog item.

      Declaration

      Variables in current are the columns that are defined in the dictionary.xml file that support the database record. There is no way at runtime to add variables to the current record.

      Display

      Variables of a current record are displayed on the Glide Forms and Lists throughout the applications that use them.

      Access and Assignment

      To access the variables or assign values to the variables within the workflow activity, get the value from the current record by referencing the Glide Element.
      var myVarValue = current.getElement(nameOfTheField);
      or
      var myVarValue = current.fieldName;
      or
      current.variableName.setValue( "A Variable Value");

      Tags:

      Feedback

          Share this page

          Got it! Feel free to add a comment
          To share your product suggestions, visit the Idea Portal.
          Please let us know how to improve this content

          Check any that apply

          To share your product suggestions, visit the Idea Portal.
          Confirm

          We were unable to find "Coaching" in Jakarta. Would you like to search instead?

          No Yes
          • Contact Us
          • Careers
          • Terms of Use
          • Privacy Statement
          • Sitemap
          • © ServiceNow. All rights reserved.

          Subscribe Subscribed Unsubscribe Last updated: Tags: January February March April May June July August September October November December No Results Found Versions Search preferences successfully updated My release version successfully updated My release version successfully deleted An error has occurred. Please try again later. You have been unsubscribed from all topics. You are now subscribed to and will receive notifications if any changes are made to this page. You have been unsubscribed from this content Thank you for your feedback. Form temporarily unavailable. Please try again or contact  docfeedback@servicenow.com  to submit your comments. The topic you requested does not exist in the release. You were redirected to a related topic instead. The available release versions for this topic are listed There is no specific version for this documentation. Explore products Click to go to the page. Release notes and upgrades Click to open the dropdown menu. Delete Remove No selected version Reset This field is required You are already subscribed to this topic Attach screenshot The file you uploaded exceeds the allowed file size of 20MB. Please try again with a smaller file. Please complete the reCAPTCHA step to attach a screenshot
          Log in to personalize your search results and subscribe to topics
          No, thanks Login