Workflow Variable Returning Undefined

kristenankeny
Tera Guru

I am running this simple script in a run script activity for a workflow running on the rm_enhancement table:

workflow.variables.skip = 'no';
gs.log('Beginning= ' + workflow.variables.skip,'EnhancementApprovals');

 

The log keeps returning "Beginning = undefined". What am I missing? Why can I not set a workflow variable in this workflow?

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kristen,

You can only get the workflow variables which are defined in input.

if your workflow is having one of the input variable with name as skip then workflow.variables.skip would give you some value.

Usually workflow variables are used when you call sub workflow in main workflow and pass variables to sub workflow and define workflow input variables to hold those values.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/using-workflows/concept/c_UsingVariablesInAWorkflow.html

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

I tried the same you said, I declared same var_name in edit inputs section, as was in startFlow() passed {name:value}. 

I was updating current record field value, in workflow Run Script activity, but nothing was updated ,as it's showing nothing.

 

@Nikhil Kumar 

check this link where I have shared solution with example on passing the inputs to workflow

Please mark that response as helpful

Trouble Accessing variables from inbound action

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

SatheeshKumar
Kilo Sage
hey i think there was a small mistake in the script line Try the below line instead gs.log('Beginning= ' + workflow.variables.skip+'EnhancementApprovals');