The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Setting email notification dynamically based on the environment the user is in

ndejoya
Tera Contributor

Hello! 

 

Still learning the ins and outs of ServiceNow and the the different things that can be done with email notifications. I have an existing email notification that needs its conditions to be updated. Right now, in the 'Who will receive' tab, there is Groups SNOW Dev and SNOW Test. What's being asked, where I'm not sure how to go about, is the email notification should be dynamically set based on the environment you are in. Would anyone be able to guide a relatively new ServiceNow user on how to do this? Thank you for the time!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ndejoya 

how are you triggering the email? using event or directly using the notification "Inserted" and "Updated" checkboxes?

To handle dynamic recipient you should use after business rule & create event on the same table as that of the notification

Then based on your logic you can set the recipients via triggering the event.

I hope I have answered your question and you can enhance it further based on your requirement.

1) create event on your table

AnkurBawiskar_0-1744685559490.png

 

2) make notification trigger on that event, ensure "Event parm1 contains recipient" is checked

AnkurBawiskar_1-1744685587203.png

 

AnkurBawiskar_2-1744685664118.png

 

3) use business rule to trigger the event

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

    // Add your code here
    var recipient = '';
    var instanceName = gs.getProperty('instance_name');
    if (instanceName == 'dev instance')
        recipient = 'groupSysIdForDev';
    else if (instanceName == 'test instance')
        recipient = 'groupSysIdForTest';

    gs.eventQueue('event_name', current, recipient);

})(current, previous);

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

View solution in original post

10 REPLIES 10

@ndejoya 

I already shared a working approach below.

Did you get a chance to check?

It should work for you and you can enhance it as per your case.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@ndejoya 

how are you triggering the email? using event or directly using the notification "Inserted" and "Updated" checkboxes?

To handle dynamic recipient you should use after business rule & create event on the same table as that of the notification

Then based on your logic you can set the recipients via triggering the event.

I hope I have answered your question and you can enhance it further based on your requirement.

1) create event on your table

AnkurBawiskar_0-1744685559490.png

 

2) make notification trigger on that event, ensure "Event parm1 contains recipient" is checked

AnkurBawiskar_1-1744685587203.png

 

AnkurBawiskar_2-1744685664118.png

 

3) use business rule to trigger the event

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

    // Add your code here
    var recipient = '';
    var instanceName = gs.getProperty('instance_name');
    if (instanceName == 'dev instance')
        recipient = 'groupSysIdForDev';
    else if (instanceName == 'test instance')
        recipient = 'groupSysIdForTest';

    gs.eventQueue('event_name', current, recipient);

})(current, previous);

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

@ndejoya 

Hope you are doing good.

Did my reply answer your question?

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

Apologies for the delayed response, thank you for the time you took to help me! I have not yet tried it, but I understand the logic. Trying today, and hoping it works. Thank you!

@ndejoya 

Glad to help.

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