Dynamically create catalog tasks based on list collector selections
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 06:03 PM
Hi Everyone,
I would like to create a catalog task for each selection chosen in a list collector.
I only have 2 variables: sc_short_desc and sc_site (which is a list collector)
So if a user choses 3 sites in the list collector, then I would like 3 catalog tasks raised:
Catalog task 1: short description and site 1
Catalog task 2: short description and site 2
Catalog task 3: short description and site 3
I am assuming you do this in the workflow using Run Script. I would also like to wait for all of the catalog tasks to be completed before moving on to the next part of the workflow.
I am new to ServiceNow scripting so any help is appreciated.
Cheers
Troy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 06:25 PM
The items selected in a List Collector variable are stored in a comma separated string such as "2a826bf03710200044e0bfc8bcbe5de7,46c6f9efa9fe198101ddf5eed9adf6e7".
You will have to use this to get sc_site.
Query on Catalog task table with your RITM as parent in wait for condition activity. Set workflow.scratchpad to sys_id of TASK while creating it and then use scratchpad value in wait for condition to get the task.
Thanks,
D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 08:45 PM
Thanks for the reply D,
I was hoping for a bit of sample code to mess around with to automatically create the tasks with the individual sites as my java scripting skills are very limited to non-existent. Is anyone able to help?
Cheers
Troy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 04:24 PM
After trolling through some other threads I have managed to create the following script which dynamically creates multiple catalog tasks depending on how many sites are chosen in the list collector:
var array1 =[];
array1 = current.variables.sc_site.toString();
var array2 = [];
array2 = array1.split(',');
var Length = array2.length;
for (var i =0; i< Length; i++){
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.short_description = current.variables.sc_short_desc;
gr.assignment_group = '92c515ed4fc19e006a6aa90f0310c7ff';
gr.cmdb_ci = '3dcb98e34ff3de8424c49a701310c7c7';
gr.insert();
if(gr.next());
}
Next step is to figure out how to add to the script to pass the sc_site variable over to the individual catalog tasks. Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:44 AM
I want set value fro short description as location name