Create catalog task based on List collector and set assignment group

Community Alums
Not applicable

Hi All,

We have a requirement to create separate task for each option selected in the list collecter and also set assignment group. List collector is referencing to "u_list_collector_table" and we have a reference field(Assignment Group) in this table that references to group table. I'm able to create task for each option selected in list collector but unable to set assignment group. Can someone help me on this?


Below is my code in Run Script activity:

var reports = current.variables.u_list_collector_variable.getDisplayValue().split(',');
for (i = 0; i < reports.length; i++) {
    var tabl = new GlideRecord('u_list_collector_table');
    tabl.get(reports[i].toString);
 
    var sct = new GlideRecord('sc_task');
    sct.initialize();
    sct.short_description = reports[i] + ' Access Request';
    sct.assignment_group = tabl.u_assignment_group.toString();
    sct.request_item = current.sys_id;
    sct.order = 100;
    sct.state = '1';
    sct.insert();
}
7 REPLIES 7

Community Alums
Not applicable

Community Alums
Not applicable

Hi @Community Alums 

Thanks for the quick response. I tried the soultion which is there in the link provided by you but no luck.

var abc = current.variables.abc_reports; // Variable name in your catalog item
 
var xyz = abc.toString().split(',');
for(var i=0; i<xyz.length;i++){
 
var gr = new GlideRecord("sc_task");
gr.initialize();
gr.parent = current.sys_id;
gr.short_description="short description to set";
gr.request=current.request;
gr.request_item = current.sys_id;
gr.assignment_group =  xyz[i];
gr.insert();
}

 

 

Community Alums
Not applicable

@Community Alums  if you have 5min for a quick call to troubleshoot?

Meeting Link: meet.google.com/jdo-fvog-ifh

 

Riya Verma
Kilo Sage
Kilo Sage

HI @Community Alums ,

 

Please try using below script:

var selectedOptions = current.u_list_collector_field.split(","); 

// Create a new task for each selected option
for (var i = 0; i < selectedOptions.length; i++) {
  var newTask = new GlideRecord('task'); /
  newTask.initialize();
  var assignmentGroup = new GlideRecord('u_list_collector_table'); 
  if (assignmentGroup.get('sys_id', selectedOptions[i])) {
    newTask.assignment_group = assignmentGroup.getValue('assignment_group'); // Assuming the reference field to the assignment group is named "assignment_group"
  }
newTask.insert();
}
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma