Assign catalog task to the multiple assignment groups selected on catalog item variable in workflow

Community Alums
Not applicable

Hello Experts,

 

I have list collector variable (assignment_group) on catalog item form referencing to a custom table and all those groups are present in sys_user_group table, I want to trigger catalog tasks to any group selected on catalog item variable while raising a request. If one group is selected then one catalog task should tigger to that particular assignment group. If multiple groups are selected that multiple catalog task should trigger to those assignment groups.

 

Please advice how can I achieve this.

Script in the catalog task activity:

var assgnmntGroup = current.variables.assignment_group.getDisplayValue();
var groupArray = assgnmntGroup.split(',');
var groupName = [];
var groupnames = [];
for (i = 0; i < groupArray.length; i++) {
    groupName = groupArray[i].trim();
    var gr = new GlideRecord('u_common_choice_values');
    gr.addEncodedQuery('u_active=true^u_catalog_item=b511385ec32a52909275be53e4013121^u_variable=de83da3d97f256d002e4b2e8c253afe7^u_valueIN' + current.variables.assignment_group.getDisplayValue());
    gr.addQuery('u_value', groupName.trim());
    gr.query();
    if (gr.next()) {
        var groups = new GlideRecord('sys_user_group');
        groups.addEncodedQuery('nameIN' + current.variables.assignment_group.getDisplayValue());
        groups.addQuery('name', groupName.trim());
        groups.query();
        if (groups.next()) {
            groupnames.push(groups.sys_id.toString());
            for (j = 0; j < groupnames.length; j++) {
                var groupSysIds = groupnames[j];
                gs.info('logs for groups ' + groupSysIds);
                task.short_description = "clusters";
                task.description = "This is a request to clusters";
                task.assignment_group = groupSysIds;
            }
        }
    }
}


With the above script am able to create only one catalog task getting assigned to last assignment group in the array. remaining are groups are ignored.


Please help me to achieve this
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Yes the tasks needed to be created parallelly. 
i used  the run script activity to achieve this scenario and it worked.
Here is the modified script:

var assgnmntGroup = current.variables.assignment_group;
if (assgnmntGroup) {
    var assgnmntgroupnames = assgnmntGroup.getDisplayValue();
    if (assgnmntgroupnames) {
        var groupArray = assgnmntgroupnames.split(',');
        for (i = 0; i < groupArray.length; i++) {
            var groupName = groupArray[i].trim();
            if (groupName) {
                var groups = new GlideRecord('sys_user_group');
                groups.addQuery('name', groupName);
                groups.query();
                if (groups.next()) {
                   // gs.info('hare hare one  ' + groupName);
                    var task = new GlideRecord('sc_task');
                    task.initialize();
                    task.short_description = "clusters";
                    task.description = "This is a request to clusters" ;
                    task.assignment_group = groups.sys_id;
                    task.request_item = current.sys_id;

                    task.insert();

         
                }
            }
        }
    }
}



View solution in original post

6 REPLIES 6

@Community Alums 

how will you associate the catalog/ritm variables on catalog task created via script?

How will the agents working on those task know what are the request details?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

As you could see the script in this thread which has 
 task.request_item = current.sys_id;
with the above link enusers all variables are associated with the task.
Hope this clarifies your question