Set Who Will Receive in email notification using a Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 01:14 AM
Hi,
I'm trying to create an email notification that is sent to the user assigned whenever any worknotes or addition comments are added. If there is no user assigned, the notification will send to a group instead. Is this possible with a script ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 01:46 AM - edited 02-20-2023 01:49 AM
Hello @Gopal6
When you are designing a notification, under the who will receive section, you have the below field:
- Users/Groups in fields
In the Users section, you can add the Assigned to, Assignment group fields.
So if there is no user added to the assigned to field, it there is a valid email for the assignment groups, then the group will be getting the email.
Unfortunately, the who will receiver section does not have script function available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 02:22 AM
Thanks for the reply. In this case, if assigned to is filled then it will send notification to Assignment group as well. This should not be the case. Only assigned to should receive the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 02:23 AM
Hi @Gopal6 ,
You can use the scripted method to send a notification using the GlideEmailOutbound api to send the email based on your conditions.
Refere below URL for further functions from this API :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 03:03 AM
Hello @Gopal6
On which Table you are trying to make this notification ?
In my case I used incident Table for Demo and when incident worknotes updated then sending the notification to assigned to or assignment group
Step 1: Create One entry in Event Registry - "inc.worknotes.updated"
Step 2 : Create One Business Rule on Incident Table
Advanced : True
When to run :
After update
condition : worknotes changes
In Advance tab write below Code:
(function executeRule(current, previous /*null when async*/ ) {
if (current.getValue('assigned_to')) {
gs.eventQueue('inc.worknotes.updated', current, current.assigned_to); //call event queue and send param 1
} else {
gs.eventQueue('inc.worknotes.updated', current, current.assignment_group.email);
}
})(current, previous);
Step 3 : Create a notification on incident table
When to Send Tab :
Send when : Event is fired
Event Name : inc.worknotes.updated
In Who will receive Tab
Make sure to check Event parm 1 contains recipient field as in business rule we are sending the param 1
Hope this works for you...!!!
You can refer the ServiceNow documentation for more information on Notifications & Events
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates