Workflow Variable

brahmandlapally
Mega Guru

I want to store a variable value in a new variable to use it in further workflow.Help me?

3 ACCEPTED SOLUTIONS

Moin Kazi
Kilo Sage
Kilo Sage

Hi @brahmandlapally ,

 

you can use the workflow_scratchpad to pass data between workflows in ServiceNow. The scratchpad allows you to store temporary data that can be accessed by the same workflow or passed to another workflow when calling it.

 

Steps to Use workflow_scratchpad:

  1. Set Data in the Scratchpad:

    • In your first workflow, use a Set Value activity to assign data to the workflow_scratchpad. For example:
      javascript
       

 

workflow_scratchpad.variableName = "your_value";

 

  • Call Another Workflow:

    • Use a Run Workflow activity to call the second workflow. In the configuration, you can pass the scratchpad variable as an input:
      • Input the scratchpad variable where required.
  • Access the Scratchpad in the Second Workflow:

    • In the second workflow, you can access the passed value from the scratchpad:
      javascript
       

 

var receivedValue = workflow_scratchpad.variableName;

 

This method enables you to transfer data between workflows effectively.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View solution in original post

VishaalRanS
Tera Guru

Hi @brahmandlapally 

 

To store a variable value in a new variable in ServiceNow for a workflow:

1. Add a Script Activity to the workflow.

 

var sourceValue = current.source_variable;                   // Get original
variablecurrent.new_variable_name = sourceValue;    // Set new variable

 

2. Save and publish the workflow.

Now you can use new_variable_name in subsequent workflow activities.

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

Sai Krishna6147
Mega Guru

Hi @brahmandlapally 

  • Depending on how you are creating the workflow, you can use either a Scripted Workflow or a Flow Designer to store a variable value in a new variable in ServiceNow for use in a workflow.

It is possible to directly assign the value of one variable to another within a workflow script or business rule. An illustration of storing a variable value in a new variable is provided here:

var originalVariableValue = current.variables.your_variable_name;
var newVariable = originalVariableValue;

 

 

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

View solution in original post

3 REPLIES 3

Moin Kazi
Kilo Sage
Kilo Sage

Hi @brahmandlapally ,

 

you can use the workflow_scratchpad to pass data between workflows in ServiceNow. The scratchpad allows you to store temporary data that can be accessed by the same workflow or passed to another workflow when calling it.

 

Steps to Use workflow_scratchpad:

  1. Set Data in the Scratchpad:

    • In your first workflow, use a Set Value activity to assign data to the workflow_scratchpad. For example:
      javascript
       

 

workflow_scratchpad.variableName = "your_value";

 

  • Call Another Workflow:

    • Use a Run Workflow activity to call the second workflow. In the configuration, you can pass the scratchpad variable as an input:
      • Input the scratchpad variable where required.
  • Access the Scratchpad in the Second Workflow:

    • In the second workflow, you can access the passed value from the scratchpad:
      javascript
       

 

var receivedValue = workflow_scratchpad.variableName;

 

This method enables you to transfer data between workflows effectively.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VishaalRanS
Tera Guru

Hi @brahmandlapally 

 

To store a variable value in a new variable in ServiceNow for a workflow:

1. Add a Script Activity to the workflow.

 

var sourceValue = current.source_variable;                   // Get original
variablecurrent.new_variable_name = sourceValue;    // Set new variable

 

2. Save and publish the workflow.

Now you can use new_variable_name in subsequent workflow activities.

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

Sai Krishna6147
Mega Guru

Hi @brahmandlapally 

  • Depending on how you are creating the workflow, you can use either a Scripted Workflow or a Flow Designer to store a variable value in a new variable in ServiceNow for use in a workflow.

It is possible to directly assign the value of one variable to another within a workflow script or business rule. An illustration of storing a variable value in a new variable is provided here:

var originalVariableValue = current.variables.your_variable_name;
var newVariable = originalVariableValue;

 

 

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.