Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Limite who wil receive notification

Paulo Machado
Kilo Sage

Hi everyone,
Based on a new incident record, both the Caller and the Opened by users should receive a notification. However, if either of them belongs to the Help Desk group, that user should not receive the notification.

Example:
If the Caller is part of the Help Desk group and Opened by is not, only the Opened by user should receive the notification — and vice versa.

How can we implement this logic?

Thanks in advance!



1 ACCEPTED SOLUTION

Vishal Jaswal
Giga Sage
Giga Sage

Hello @Paulo Machado 

Below are the steps:

1. Create a system property for Help Desk Group sys_id (Table: sys_properties.LIST) --> Best practice to not hard code sys_id and have roles associated with the sys property

VishalJaswal_0-1744899308109.png



2. Create an Event (Table: sysevent_register)

VishalJaswal_1-1744899400558.png

 

3. Create email notification (Table: sysevent_email_action)

VishalJaswal_4-1744900038301.png

 

VishalJaswal_5-1744900053088.png


4. Create an insert Business Rule on Incident Table:

VishalJaswal_2-1744899432141.png

(function executeRule(current, previous /*null when async*/) {
   var helpDeskGroupId = gs.getProperty('helpdesk.group.sysid'); 


   function validateUserHelpDeskMembership(userId) {
       var grUsr = new GlideRecord('sys_user_grmember');
       grUsr.addQuery('user', userId);
       grUsr.addQuery('group', helpDeskGroupId);
       grUsr.query();
       return grUsr.hasNext();
   }
   
   if (!current.caller_id || !current.opened_by) {
       return;
   }
   
   var callerValidation = validateUserHelpDeskMembership(current.caller_id);
   var openedByValidation = validateUserHelpDeskMembership(current.opened_by);
   
   if (callerValidation && openedByValidation) {
       gs.log('VJ1: Email will be sent to Opened By: ' + current.opened_by.email);
       gs.eventQueue('incident.custom_notify', current, current.opened_by.email, '');
   }
})(current, previous);


Validation Results:

VishalJaswal_3-1744899475443.png

 




Hope that helps!

View solution in original post

5 REPLIES 5

@Vishal Jaswal

It's not working — the email was only sent to the caller, and the 'opened_by' didn't receive anything. Also, 'opened_by' is not a member of the Help Desk group.