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

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Paulo Machado 

 

I think with just one notification, it's not possible. You need to create two notifications, each with different conditions. Now, the question is how to check if a user is part of a group or not, which you'll need to verify.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@Paulo Machado 

Only 1 notification required

you can use after insert business rule and trigger the event from that business rule and determine the recipient dynamically based on group membership

Link that event with notification

I hope you can configure notification, event and the content using docs

After Insert BR:

(function executeRule(current, previous /*null when async*/) {
    // Get the Caller and Opened by users
    var caller = current.caller_id;
    var openedBy = current.opened_by;

    // Function to check if a user is in the Help Desk group
    function isInHelpDeskGroup(user) {
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.addQuery('group.name', 'Help Desk');
        gr.query();
        return gr.hasNext();
    }

    // Check if the Caller is in the Help Desk group
    var callerInHelpDesk = isInHelpDeskGroup(caller);

    // Check if the Opened by user is in the Help Desk group
    var openedByInHelpDesk = isInHelpDeskGroup(openedBy);

    // Send notifications based on the group membership
    if (!callerInHelpDesk) {
        gs.eventQueue('incident.notify.caller', current, caller, null);
    }

    if (!openedByInHelpDesk) {
        gs.eventQueue('incident.notify.opened_by', current, openedBy, null);
    }
})(current, previous);

In Email Notification "Event parm1 contains Recipient" Should be true

Event: on incident table

AnkurBawiskar_0-1744897615534.png

 

Notification: on incident table

AnkurBawiskar_1-1744897650671.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Paulo Machado 

Thank you for marking my response as helpful.

I believe I have also answered your query.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vishal Jaswal
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!