Dynamic workflow scratchpad variable names

arabeau
Kilo Contributor

Hi All,

hoping someone can help with this... basically what I want to do is do a glide record query and loop through returned results to set a workflow.scratchpad variable with a .name of a returned gr.value

ie, creating a workflow.scratchpad variable with the variable's name equal to the value of gr.number for example

say looping through 3 glide record results on the incident table I want to set variables like the below

 

workflow.scratchpad.INC0001011 = someOtherValue;

workflow.scratchpad.INC0001012 = anotherOtherValue;

workflow.scratchpad.INC0001013 = yetAnotherOtherValue;

 

so that later on in my workflow I can reference the value of workflow.scratchpad.INC0001012

 

conceptually I want something like this, but I believe its just going to keep overwriting workflow.scratchpad.varName

 function setVariable(varName, value) {
  workflow.scratchpad.varName = value;
 }

 

anyone have any suggestions on how to do this, or suggestions on other ways to set a dynamic list of workflow.scratchpad.variables? Any help greatly appreciated!

 

Ajay

1 ACCEPTED SOLUTION

here is an example, looping through a GR. This sample will create properties on scratchpad that are the sys_id (getUniqueValue()) of each record, and the value of that property gets set to the display value of that record.

while (gr.next()) {
  workflow.scratchpad[gr.getUniqueValue()] = gr.getDisplayValue();
}

View solution in original post

3 REPLIES 3

Jon Barnes
Kilo Sage

workflow.scratchpad is a js object, so you can get/set properties on a JS object one of 2 ways:

  1. workflow.scratchpad.name = value;
  2. workflow.scratchpad['name'] = value;

and for getting the values using option 2:

return workflow.scratchpad['name'];

Option 2 is the way to go for your use case

here is an example, looping through a GR. This sample will create properties on scratchpad that are the sys_id (getUniqueValue()) of each record, and the value of that property gets set to the display value of that record.

while (gr.next()) {
  workflow.scratchpad[gr.getUniqueValue()] = gr.getDisplayValue();
}

thanks jon, you rock!