how can i pass a workflow scratchpad variable to a sub workflow

dave_edgar
Mega Guru

I have defined a scratchpad variable and thought these would carry accross to subworkflows but there are.

Parent workflow > runscript step:

workflow.scratchpad.var1 = 'test';

> subworkflow > runscript step:

gs.log('workflow.scratchpad.var1 ' +  workflow.scratchpad.var1);

 

results in:

workflow.scratchpad.var1undefined

 

what am i doing wrong, currently very tired and confused

7 REPLIES 7

Okay, your screenshot looks like your workflow is running against the 'sc_req_item' table.  Is that correct?  If so, you'll need to use Workflow Catalog Variables.  You can access these from the hamburger menu.  These variables (and their values) are accessed in the same way you would access a regular catalog variable from script.

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/conc...

Marc, your reply to Dave is most helpful.   Dave's sentiment is often mine and I really appreciate clear answers from the community.

I have an additional question.  I'm trying to rewrite three workflows that run against three separate catalog items to use a subflow for some complicated shared logic. 

That logic currently uses scratchpad variables as inputs and internally.  I assume the scratchpad is available internally, but what about passing in the values currently held in the scratchpad.   Does this instruction explain how to do this, that is, assign the scratchpad to new un-linked catalog values?

If a workflow is associated with Requested Item [sc_request_item], and is not specifically associated with a catalog item, any catalog variable with a blank Cat Item field value is available to all catalog task activities within the workflow.


KristyS
Kilo Guru

If you want to pass any values to sub flow by using the Edit Inputs then you need to change the value of glide.workflow.enable_input_variable   property     to true.

 

Then using scratch pad you can pass the values to created inputs.