Set Who Will Receive in email notification using a Script

Gopal6
Tera Contributor

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 ?

7 REPLIES 7

SatyakiBose
Mega Sage

Hello @Gopal6 

When you are designing a notification, under the who will receive section, you have the below field:

  • Users/Groups in fields
    SatyakiBose_0-1676886323623.png

     

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.

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.

Anubhav24
Mega Sage
Mega Sage

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 :

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideEmailOutbou...

Vishal Birajdar
Giga Sage

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"

VishalBirajdar7_0-1676890259770.png

 

Step 2 : Create One Business Rule on Incident Table

Advanced : True

When to run : 

After update 

condition : worknotes changes

 

VishalBirajdar7_1-1676890389989.png

 

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);

 

VishalBirajdar7_2-1676890514896.png

 

 

Step 3 : Create a notification on incident table 

When to Send Tab :

Send when : Event is fired

Event Name : inc.worknotes.updated

VishalBirajdar7_3-1676890714295.png

 

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 

 

VishalBirajdar7_5-1676890884652.png

 

Hope this works for you...!!!

You can refer the ServiceNow  documentation for more information on Notifications & Events

 

 

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates