Copy Assignment group from SCtask to RITM for parallel SC Tasks

Indira8
Kilo Sage

Hi All,

 

We have a requirement to copy the assignment group on the SC Task to the corresponding RITM.

In case of multiple tasks, when the 1st task is closed, the the assignment group of the 2nd open task should be reflecting as the assignment group of the RITM. If all the tasks are closed then the assignment group of the RITM should be empty value. The following script is working for Sequential tasks but not for parallel tasks. 

For a particular catalog item, one task is created and the assignment group is reflecting as per script, but when that task is closed, then 2 parallel tasks are created and the assignment group on ritm is emptied as per the 1st task closure and the script is not considering the remaining 2 parallel tasks created. 

Could you please help with the issue in the script:

 

Business rule : After insert/update :

var gr_item = new GlideRecord('sc_req_item');
gr_item.addQuery('sys_id', current.request_item);
//current.orderByDesc('closed_at');
gr_item.query();
while (gr_item.next()) {
if (current.active == true) {
gr_item.assignment_group = current.assignment_group;
gr_item.update();
} else {
gr_item.assignment_group = " ";
gr_item.update();
}
}
})(current, previous);

 

Thank you

6 REPLIES 6

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Indira8 ,

 

Can you please try with the below code plz

 

(function(current, previous) {
    var ritmSysID = current.request_item;
    // Check if there are open tasks related to the same RITM
    var openTasks = new GlideRecord('sc_task');
    openTasks.addQuery('request_item', ritmSysID);
    openTasks.addQuery('active', true);
    openTasks.query();
    // If there are open tasks, get the assignment group from the first open task
    if (openTasks.next()) {
        var assignmentGroup = openTasks.assignment_group.toString();
        // Update the RITM assignment group
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(ritmSysID)) {
            ritm.assignment_group = assignmentGroup;
            ritm.update();
        }
    } else {
        // If no open tasks, set the RITM assignment group to empty
        var emptyAssignmentGroup = '';
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(ritmSysID)) {
            ritm.assignment_group = emptyAssignmentGroup;
            ritm.update();
        }
 }

})(current, previous);

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Hi @Danish Bhairag2  , do we need to write the Business rule on the RITM table 

Thank you 

Hi @Indira8 ,

 

No on SCTask table we need to write the BR after insert/update

 

Thanks,

Danish 

@Danish Bhairag2 - if we are writing Business rule on the SC Task table then again we are querying the sc_rask table her e var openTasks = new GlideRecord('sc_task')