- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 07:03 AM
Morning!
I am looking to generate tasks based on selection of values from a list collector that I have added to a catalog item.
I.E.> if multiple values are selected, generate tasks out to those teams
Selections == Workday;OKTA;Sailpoint
Workday > Send task to workday services
OKTA > Send task to Okta Servicesa
Sailpoint > Send task to Sailpoint Services
Currently i have 6 list collector fields that contain different reference qualifiers limting data points coming from the applications table in CMDB. The values from these list collectors then will need to generate SCTASKS when selected to the assignment group indicated on the CI record.
Looking for advice on the best practices of how to achieve this.
Thank you in advance!
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 07:19 AM
You'll want to use a 'Run script' activity in your request item workflow to do this. The script will iterate through the values in the list collector variable and then create an 'sc_task' record for each one.
// Create 'sc_task' records for each item in the list collector var
var options = current.variables.MY_LIST_COLLECTOR_VAR_NAME;
// Iterate through the options
for (i=0; i < options.length; i++) {
// Query for the current CI
var ci = new GlideRecord('cmdb_ci');
ci.get(options[i]);
// Create a new task record for the current CI
var sct = new GlideRecord('sc_task');
sct.initialize();
sct.short_description = 'Task for ' + ci.name;
sct.assignment_group = ci.assignment_group; // Make sure this field name is correct!
sct.request_item = current.sys_id;
sct.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 07:19 AM
You'll want to use a 'Run script' activity in your request item workflow to do this. The script will iterate through the values in the list collector variable and then create an 'sc_task' record for each one.
// Create 'sc_task' records for each item in the list collector var
var options = current.variables.MY_LIST_COLLECTOR_VAR_NAME;
// Iterate through the options
for (i=0; i < options.length; i++) {
// Query for the current CI
var ci = new GlideRecord('cmdb_ci');
ci.get(options[i]);
// Create a new task record for the current CI
var sct = new GlideRecord('sc_task');
sct.initialize();
sct.short_description = 'Task for ' + ci.name;
sct.assignment_group = ci.assignment_group; // Make sure this field name is correct!
sct.request_item = current.sys_id;
sct.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:33 PM
Mark, thank you! I was able to modify what you provided to accommodate the 6 list collectors, via an array.
I have attached my progress so far below, in the event that someone else is looking to provide a similar function with multiple list collectors.
// Collect the application selections from all 6 list collectors
var array = [];
var options1 = current.variables.YOUR_VARIABLE1;
var options2 = current.variables.YOUR_VARIABLE2;
var options3 = current.variables.YOUR_VARIABLE3;
var options4 = current.variables.YOUR_VARIABLE4;
var options5 = current.variables.YOUR_VARIABLE5;
var options6 = current.variables.YOUR_VARIABLE6;
if (options1 != '') {
array.push(options1);
}
if (options2 != '') {
array.push(options2);
}if (options3 != '') {
array.push(options3);
}if (options4 != '') {
array.push(options4);
}if (options5 != '') {
array.push(options5);
}if (options6 != '') {
array.push(options6);
}
//array + = options1 +","+options2 + +"," + options4 +","+ options5 +","+ options6;
gs.log(array.toString());
var data = array.toString();
var data1 = data.split(",");
gs.log(data1.length);
for (var i=0; i < data1.length; i++) {
// Create sctasks for each selected application
var sct = new GlideRecord('sc_task');
sct.initialize();
sct.short_description = 'Task for granting ' + sct.cmdb_ci + 'access' ;
sct.cmdb_ci = data1[i];
sct.assignment_group = sct.cmdb_ci.assignment_group;
sct.request_item = current.sys_id;
sct.insert();
gs.log(sct.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 08:04 AM
Am able to create multiple catalog tasks but it is not mapping the field in catalog task. I have attached the code. Please help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 10:19 AM
Just checking on on this one. Has this question been answered or is there more information I can help you with? If it's been answered, please mark the answer above as the correct one so people know this has been taken care of. Thanks!