Dynamically create catalog tasks based on list collector selections

troys
Kilo Contributor

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

9 REPLIES 9

Hi,



Did you find a solution on setting the short description value as the location name?



stuck on a the same issue


Hi Troy,



Did you find a solution for this?



Best regards,


Hi rody, I had implemented the same in below thread


List collector dynamic catalog task issue


Regards
Harish

Appy2
Tera Contributor

Hi Harish,

I have the same requirement so i used the same code suggested by you but issue here is its creating task only once.

Kindly help me here.

below code i used in workflow run script:

var array1 =[];
array1 = current.variables.application.toString();
var array2 = [];
array2 = array1.split(',');
var Length = array2.length;
gs.log('task length: '+Length);
for (var i =0; i<= Length; i++)
{
var result = array2[i];
gs.log('task result: '+result);
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.short_description = 'Task for testing';
gr.assignment_group = applicationFulfillmentGroup(result); // I am able to set support group now
gs.log('task group: '+gr.assignment_group);
gr.insert();
}
function applicationFulfillmentGroup(id) {
var gr = new GlideRecord('mycustomtable');
if (gr.get(id)) {
return gr.u_group1;
}
return;
}

Sharique Azim
Mega Sage

Hi Troy,



I had done completed this same requirement few days back and realised there has to be a limit to the number of tasks you create. for safety purpose limit it to   less than 10,while using the script method.



Better to use catalog tasks from workflow, use switch to transition tasks.