Create Email Notification via Event in ServiceNow

 

Create Email Notification via Event

Summary

This article describes the step-by-step process of How to Configure / Automate "Email Notification via Event".

Use Case

When a logged-in user changes the priority of an existing incident record then email notification should
be sent to the caller.

Email notification should contain the values such as:
1. User Name who changed the priority
2. Value of changed priority

Steps

Register an Event in the Event Registry
  • Navigate to > event registry (sysevent_register) table
  • Click on the New button to create a new event
  • Give it a name & choose the Incident table
  • Fired by: business rule
  • Click on the Save button

Create a Business Rule

A business rule is nothing but an object that will trigger/run whenever any server operations happen (i.e. when a record is created, updated, etc.).

Now we will write a business rule, to trigger the event. Once the event will get triggered it will trigger the Notification as well. 

  • Navigate to > Business rule (sys_script) table
  • Click on the New button to create the new business rule
  • Provide a name & choose the Incident table
  • Checkmark on the Active & Advanced
  • In the "When to run" tab, choose After business rule & checkmark on the Update based on the user requirement

  • Under the "Advanced" tab, we need to write the SCRIPT
  • Click on the Save button


SCRIPT

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

// Add your code here

previous.priority.changes();
gs.eventQueue('demo.event.registry', current, gs.getUserDisplayName(), current.priority);

})(current, previous);

Note:

It is worth noting that an event can be also triggered by a Workflow/Flow. In our case, the point of trigger for the event "demo.event.registry" is this business rule that we have just created.

Create an Email Notification
  • Navigate to > Notifications (sysevent_email_action) table
  • Click on the New button to create the new business rule
  • Provide a name & choose the Incident table
  • In the "When to send" tab > Send when: Event is fired & Event name: demo.event.registry

  • In the "Who will receive" tab > Users: System Admin & Users/Groups in fields: Caller


  • In the "What it will contain" tab > Subject: Demo Priority Changed Notify & Message HTML


  • Click Save

Now we have successfully created the Event and have also successfully modified the Notifications to be triggered by the event.

Testing Email Notification

Now, open an incident and change the priority. Navigate to the Email logs and check if the email notification has been triggered from the event. 

As you can see in the screenshot the notification has been triggered from the event.



NOTE:

You can also send reminders (notifications) via Flow Designer. In this article, you can find more info on how to do that.

Good to know:

Email notifications VS Inbound email actions

The basic difference is in email notification, email are sent from an instance. Whereas in inbound email action, certain actions are triggered depending on the email coming into the instance. (source)

References

  • https://www.youtube.com/watch?v=K4J9oay7Zwk&ab_channel=BasicoServiceNowLearning
  • https://tech.forums.softwareag.com/t/servicenow-email-notification-via-event/237437


Comments

Popular Posts