Need to reduce the email notification when at-mentioned and asiggned to 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-1716450193644.pngvinuthv_1-1716450201052.png

 

vinuthv_2-1716450209776.png

2. Activity Stream @Mention Email

vinuthv_3-1716450229233.png

vinuthv_6-1716450265220.pngvinuthv_7-1716450272329.pngvinuthv_8-1716450280273.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 assignee 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.

 

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

 

Thanks,

Vinuth

 

 

 

 

2 REPLIES 2

Abhit
Tera Guru

@vinuth v 

You can achieve this by 2 ways:
First: 
Write a BR on sys_email and abort on the emails based on your condition.

Second: Enable the Allow digest on the notification and ask your user to update their preference for the notifications to be received. 


Cheers!!
 

Hi @Abhit 

 

I tried with the BR, like below

I have changed in the notification like this

vinuthv_0-1717140400968.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_1-1717140418920.pngvinuthv_2-1717140432612.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