asifnoor
Kilo Patron

Hi,

In this article, I am going to explain to you about the Events feature in ServiceNow and how to use it and where all you can use this wonderful feature. 

In general software development terminology, Events is basically an action or occurrence mostly originated from external development environment or through some script. It is the same concept in ServiceNow as well.

Events in ServiceNow are mainly used either to record into the system when certain conditions occur or to take some action based on the occurrence of this event.

So To use Events, firstly you need to create an event in the system.

System Policy -> Events -> Registry.

This shows the list of all events exists in the ServiceNow instance. You can create a new event by clicking on the New button.

find_real_file.png

 

Give a name to the event and select the table on which you want to generate an event. It is best practice to mention the script that is being fired to generate this event under Fired By column. Also, provide a detail description of this event.

Once an event is created, then you can see them under Event Registry, which lists down all the events.

After the event is created, you need to fire this event. Events can be triggered/fired from different ServiceNow scripts such as Business Rules, Script includes, server-side scripts, Inbound actions, etc.

You can trigger an event with the below command

gs.eventQueue("Event Name",current,parm1,parm2);
  • Event Name refers to the name of the event that you have created earlier. 
  • Current refers to GlideRecord Object
  • parm1 and parm2 are custom parameters that you can pass to this event

Once the above command is executed, the event is triggered and you can check them in the Event log

System Policy -> Events -> Event Log

find_real_file.png

 

Once the Event is fired, then there should be event listeners which can perform an action based on this event. We can simply create/update any record based on the event in any other table or fire a notification based on this event or change the state of the workflow.

 

How can we trigger a notification using Events

 

Go to System Notifications -> Email -> Notifications

Create New notification, select the table on which you want to trigger the notification and then select the event name under "When to send". Refer to below screenshot.

find_real_file.png

 

How to perform any create/update based on event

 

Go to System Policy -> Events -> Script Actions

Create New and select the event on which this script action to be executed. Then under Script, you can write your code as per your requirement.

find_real_file.png

 

I have also written another article with an example of how to trigger a notification with the help of Business rules and Events. 

Setup Email Notification with Events and Business Rules

If you find this article helpful, kindly mark the article as helpful and bookmark it.

Comments
Hetang Modi
Tera Contributor
gs.eventQueue("Event Name",current,parm1,parm2);

How can one access `parm1` and `parm2` from the script actions?

Steps followed:

  1. Create a Event Registry for a custom table.
  2. Create a BR on that custom table to invoke/trigger the above created event and passed the parameters as mentioned above.
  3. Using a script action, I can access the `current` parameter, but not the other two. How do we access it?

 

BananaChips
Tera Explorer

@Hetang Modi You can use/assign the passed parameters by calling them using "event." as a prefix, like "event.parm1" and "event.parm2".

var a = event.parm1.string(); 
template.print(a);

 
This page may be helpful as well.

Version history
Last update:
‎05-01-2019 12:51 AM
Updated by: