Based on list collector values , create catalog task in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 01:50 AM
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
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 04:41 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 12:52 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 12:57 AM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:18 AM
Hello,
You will check in for loop that how many times it is iterating.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:22 AM
Sorry Don't catch you