Need to limit the email notifications if assigned to person and at-mentioned both are same.

vinuth v
Tera Expert

Hi All,

 

I Need to reduce the email notification when at-mentioned and assigned to both are same in the task.

Currently 2 email notification will trigger, when assigned to person and at-mentioned person both are same, I need to reduce the notification to one. Only one notification should trigger that is at-mentioned notification and "${number} has had work notes added" notification should not trigger.

 

1. Assigned Catalog Task Worknoted

vinuthv_0-1717139468715.pngvinuthv_1-1717139481143.pngvinuthv_2-1717139496385.png

 

2. Activity Stream @Mention Email

vinuthv_3-1717139517837.pngvinuthv_4-1717139526262.pngvinuthv_5-1717139534839.pngvinuthv_6-1717139543020.png

Note: "Activity Stream @Mention Email" this notification is applicable to all the tables in servicenow when user mentioned the @User email will trigger.

If assign to person and at-mention both are different two email notification will trigger for the task.

 

Here I need to do the modification on the " Assigned Catalog Task Worknoted" notification, because If I do the changes on the "Activity Stream @Mention Email" notification it will effect to other tables in ServiceNow.

 

For this I have changed in the notification like this

vinuthv_7-1717139722857.png

Added the conditions in the Business Rule like below. I wrote the Business Rule on the sc_task table. Using when condition as before update.

vinuthv_8-1717139794629.pngvinuthv_9-1717139812303.png

 

Script;

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var taskGR = new GlideRecord('sc_task');
    taskGR.addQuery('number', current.number);
    taskGR.query();
    while (taskGR.next()) {
        var assign = taskGR.assigned_to.getDisplayValue();
        gs.info("testvinuth9 " + assign);
        var workNotes = '';
        var workNotesGR = new GlideRecord('sys_journal_field');
        workNotesGR.addQuery('element_id', taskGR.sys_id);
        workNotesGR.addQuery('element', 'work_notes');
        workNotesGR.orderByDesc('sys_created_on');
        workNotesGR.query();
        if (workNotesGR.next()) {
            workNotes = workNotesGR.getValue('value');
        }
        if (workNotes.includes('@' + assign)) {
            gs.log("includes20vinuth" + assign);
            var Email = new GlideRecord('sysevent_email_action');
            Email.addQuery('sys_id', '4bab8335139162009c89b53a6144b008');
            Email.query();
            if (Email.next()) {
                Email.recipient_fields = 'watch_list' + ',' + "request_item.work_notes_list";
                Email.update();
            }
            gs.eventQueue('Limit number of emails sent', taskGR);
        } else  {
            gs.log("does not includes 30vinuth" + assign);
           var Email = new GlideRecord('sysevent_email_action');
                Email.addQuery('sys_id', '4bab8335139162009c89b53a6144b008');
                Email.query();
                if (Email.next()) {
                    Email.recipient_fields = 'assigned_to' + ',' + 'watch_list' + ',' + 'request_item.work_notes_list';
                    Email.update();
                }
                gs.eventQueue('Limit number of emails sent', taskGR);
            }
}
        gs.log("test40vinutha" + workNotes);
        //gs.print(workNotes);
    }

})(current, previous);

 

This script is working fine for some scenarios but If I had some work notes without mentioning any person at that time email will not triggering to the assigned to person. 

Please any one suggest me, how to reduce the email notification if the assignee to person and at-mention both are same.

 

Thanks,

Vinuth

1 REPLY 1

Mark Manders
Mega Patron

It doesn't really help to ask the same question every week and ignore the answers already given. 

Please build on the answers already provided, so people that are spending their time to help you, know what already has been done and what doesn't work when you tried it: 
https://www.servicenow.com/community/developer-forum/limit-number-of-emails-sent-when-at-mentioned-w...

https://www.servicenow.com/community/developer-forum/need-to-reduce-the-email-notification-when-at-m...

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark