Based on list collector values , create catalog task in workflow

vinzz
Kilo Contributor

Hi,

 

I have a catalog item, which contains a list collector that reference to assignment groups of servicenow.

Requirement is to create catalog task for all the assignment groups selected in list collector.

Please advice.

 

Thanks in advance

15 REPLIES 15

vinothkumar
Tera Guru

Try something like this.

 

var group = current.variables_pool.u_group;

var groups = group.split(",");
gs.log(group);
gs.log(groups);


var m = new GlideRecord("sc_task");
m.initialize();

for(var i=0;i<groups.length; i++){


task.assignment_group = groups[i];
task.insert();


}

Hi,

 

I managed to write the script based on solution shared by everyone.But now an additional task is created with blank assignment group..

Eg -

-selected two assignment group in list collector, 3 task are created, two with correct group name & one additional task with blank assignment group.

-selected three assignment group in list collector, 4 task are created, three with correct group name & one additional task with blank assignment group.

 

NOT SURE WHY AN ADDITIONAL TASK GETTING CREATED.

Script-

var abc = [];
var abc = current.variables.u_group;
var xyz = [];
var xyz = abc.toString().split(',');
gs.log(xyz);
gs.log(xyz.length);

for(var i=0;i<xyz.length; i++){
var gm = new GlideRecord("sc_task");
gm.initialize();
gm.parent = current.sys_id;
gm.request = current.request;
gm.short_description = "default task name";  //have a default task name
gm.request_item= current.sys_id;
gm.assignment_group=xyz[i];
//gm.assignment_group.setDisplayValue(xyz[i]);
//task.assignment_group = groups[i];
gm.insert();
}

vinzz
Kilo Contributor

Hi,

 

I managed to write the script based on solution shared by everyone.But now an additional task is created with blank assignment group..

Eg -

-selected two assignment group in list collector, 3 task are created, two with correct group name & one additional task with blank assignment group.

-selected three assignment group in list collector, 4 task are created, three with correct group name & one additional task with blank assignment group.

 

NOT SURE WHY AN ADDITIONAL TASK GETTING CREATED.

Script-

var abc = [];
var abc = current.variables.u_group;
var xyz = [];
var xyz = abc.toString().split(',');
gs.log(xyz);
gs.log(xyz.length);

for(var i=0;i<xyz.length; i++){
var gm = new GlideRecord("sc_task");
gm.initialize();
gm.parent = current.sys_id;
gm.request = current.request;
gm.short_description = "default task name";  //have a default task name
gm.request_item= current.sys_id;
gm.assignment_group=xyz[i];
//gm.assignment_group.setDisplayValue(xyz[i]);
//task.assignment_group = groups[i];
gm.insert();
}

Hello,

You will check in for loop that how many times it is iterating.

Sorry Don't catch you