Passing array of values in scratchpad workflow and calling the subflow for each element in array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 01:26 AM
Hi Experts,
Please help me in storing an array of values through workflow scratchpad and passing it to subflow via workflow activity.
Here is my code
var catalog_workflow_group;
var list =current.variables.access_type.toString();
gs.log('hcv: ' + list);
var listSplit = list.split(',');
gs.log('listsplit: ' + listSplit);
for (var i = 0; i < listSplit.length; i++) {
var softwareRef = new GlideRecord('u_active_directory_software_reference');
softwareRef.addQuery('sys_id', listSplit[i].trim());
softwareRef.query();
while (softwareRef.next()) {
workflow.scratchpad.catalog_workflow_group=softwareRef.u_active_directory_group.toString();
}
gs.log('Answer sc is: ' +workflow.scratchpad.catalog_workflow_group);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 03:52 AM
Hi Vishal,
Thanks for help the subflow has setup but the array is passing only one sys ID eventhough im getting desired sys id's in logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 04:03 AM - edited 10-23-2023 04:04 AM
Hi Hemachithra ,
Can you try below code...!!!
var catalog_workflow_group;
var list =current.variables.access_type.toString();
gs.log('hcv: ' + list);
var listSplit = list.split(',');
gs.log('listsplit: ' + listSplit);
/* Declare array */
var result =[];
var softwareRef = new GlideRecord('u_active_directory_software_reference');
softwareRef.addEncodedQuery('sys_idIN' + listSplit); // query on groups from listSplit
softwareRef.query();
while (softwareRef.next()) {
result.push(softwareRef.u_active_directory_group.toString()); //push value in array
}
//set workflow scratchpad
workflow.scratchpad.catalog_workflow_group = result.toString();
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 09:07 AM
The above code returns the following sys id correctly but the subflow following this activity is triggered only once it should trigger twice as two sys id is generated.
here is the subflow and parameters passed in subflow.