I have a notification on RITM table that triggered when someone update the Add comment on ScTask.

Adityanshu Sing
Tera Contributor

I have a notification on RITM table that triggered when someone update the Additional comment on ScTask of that Ritm and we want to add one condition i.e when additional comment on ScTask is updated by assigned to then the notification should not trigger. I have add the condition in the business rule but it's not working . can someone provide the correct bussiness rule ?

 

 

 

gs.eventQueue("sc_req_item.commented", current, gs.getUserID(), gs.getUserName());
queueAssigneeEvent();

function queueAssigneeEvent() {
    var assigneeArr = [];
    var assignGroupArr = [];
    //Query for non-pending sc_task records
    var catTsk = new GlideRecord('sc_task');
    catTsk.addQuery('request_item', current.sys_id);
    catTsk.addQuery('state', '!=', -5);
    catTsk.query();
    if (!catTsk.hasNext()) {
        gs.addInfoMessage(gs.getMessage('Comment cannot be viewed by technicians until work begins on the Requested Item'));
        return;
    }
   while (catTsk.next()) {
        //notify task assignees
        if ((!catTsk.assigned_to.nil()) && (current.sys_updated_by != catTsk.assigned_to.user_name)) {
            assigneeArr.push(catTsk.assigned_to.toString());
      }
        else 
			
            assignGroupArr.push(catTsk.assignment_group.toString());
            //Add Work notes watch list users
            assigneeArr.push(catTsk.work_notes_list.toString());

        
    }
    gs.eventQueue("sc_req_item.commented.itil", current, assigneeArr, assignGroupArr);
}

 

 

 

 

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @Adityanshu Sing 

I think it is because of the assignment group. As per your code, you are preventing the user being added to the assigneeArr array but at the same time in else condition you are adding the Group to the assignGroupArr, the group will contain this user so the user is receiving the notification.

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

Hi @AnveshKumar M ,

I used logs and checked. The else condition is running when the assign to is empty whereas the If condition is running when assign to is not empty .

Amit Gujarathi
Giga Sage
Giga Sage

HI @Adityanshu Sing ,
I trust you are doing great.

 

Here's a modified version of your queueAssigneeEvent() function:

 

function queueAssigneeEvent() {
    var assigneeArr = [];
    var assignGroupArr = [];

    var catTsk = new GlideRecord('sc_task');
    catTsk.addQuery('request_item', current.sys_id);
    catTsk.addQuery('state', '!=', -5);
    catTsk.query();

    if (!catTsk.hasNext()) {
        gs.addInfoMessage(gs.getMessage('Comment cannot be viewed by technicians until work begins on the Requested Item'));
        return;
    }

    while (catTsk.next()) {
        // Check if the additional comment is updated and not by the assigned user
        if (catTsk.comments_and_work_notes.changes() && current.sys_updated_by != catTsk.assigned_to.user_name) {
            if (!catTsk.assigned_to.nil()) {
                assigneeArr.push(catTsk.assigned_to.toString());
            }
            if (!catTsk.assignment_group.nil()) {
                assignGroupArr.push(catTsk.assignment_group.toString());
            }
            // Add Work notes watch list users
            assigneeArr.push(catTsk.work_notes_list.toString());
        }
    }

    if (assigneeArr.length > 0 || assignGroupArr.length > 0) {
        gs.eventQueue("sc_req_item.commented.itil", current, assigneeArr, assignGroupArr);
    }
}
 

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi