gs.eventQueue() in ServiceNow

gs.eventQueue() method is used to trigger events programmatically. These events are defined in the Event Registry and you can associate with notifications, scripts, or other custom actions. It allows you to execute asynchronous tasks in ServiceNow.

Syntax: gs.eventQueue(eventName, record, parm1, parm2, eventQueue);

Parameters

Parameter Description Required
eventName The name of the event to trigger, as defined in the Event Registry (sysevent). Yes
record The GlideRecord of the table where the event is associated (context record for the event). Yes
parm1 (Optional) Parameter 1 to pass to the event. Commonly used in event scripts. No
parm2 (Optional) Parameter 2 to pass to the event. Commonly used in event scripts. No
eventQueue (Optional) A custom event queue name. If not provided, the default event queue is used (default). No

 

gs.eventQueue() Method

The eventQueue() method is part of the GlideSystem server-side API. The eventQueue() method inserts an event in an event queue. The eventQueue() method is typically passed four parameters but can also take an optional 5th parameter:

  1. Event name. Enclose the event name in quotes.
  2. GlideRecord object, typically current but can be any GlideRecord object from the event’s table.
  3. Any value that resolves to a string. This is known as parm1 (Parameter 1). Can be a string, variable that resolves to a string, or method that resolves to a string.
  4. Any value that resolves to a string. This is known as parm2 (Parameter 2). Can be a string, variable that resolves to a string, or method that resolves to a string.
  5. (Optional) Name of the queue to manage the event.

example:

gs.eventQueue(‘event.name’, GlideRecord, parm1, parm2); // standard form

gs.eventQueue('event_name',current,current.number,gs.getUserName());

Use Cases

If you want to send a notification when a new high-priority incident is created.

Solution

1. Register the Event

    • Navigate to System Policy > Events > Registry.
    • Create an event named incident.high_priority.

2. Add gs.eventQueue() in a Business Rule:

if (current.priority == 1) {
    gs.eventQueue('incident.high_priority', current, current.short_description, current.assigned_to.name);
}

 

3. Create a Notification:

    • Navigate to System Notification > Email > Notifications.
    • Create a new notification for the incident.high_priority event.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here