gs.eventqueue

elizabeth keen
Giga Contributor

what is gs.eventqueue in servicenow. 

1 ACCEPTED SOLUTION

shubham jagtap
Tera Guru

Generating Events

There are two ways to generate events:

  • Server-side script using the gs.eventQueue() method
  • Workflow Create Event activity

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('x_58872_needit.overdueNeedItTask',current,current.number,gs.getUserName());

you can refer below links:

https://developer.servicenow.com/app.do#!/lp/new_to_servicenow/app_store_learnv2_automatingapps_madr...

https://community.servicenow.com/community?id=community_question&sys_id=85a1d76ddbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=674f7e69db58dbc01dcaf3231f96...

after going throw this mark it as correct/helpfull.

Thank you

 

View solution in original post

5 REPLIES 5

shubham jagtap
Tera Guru

Generating Events

There are two ways to generate events:

  • Server-side script using the gs.eventQueue() method
  • Workflow Create Event activity

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('x_58872_needit.overdueNeedItTask',current,current.number,gs.getUserName());

you can refer below links:

https://developer.servicenow.com/app.do#!/lp/new_to_servicenow/app_store_learnv2_automatingapps_madr...

https://community.servicenow.com/community?id=community_question&sys_id=85a1d76ddbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=674f7e69db58dbc01dcaf3231f96...

after going throw this mark it as correct/helpfull.

Thank you

 

Alikutty A
Tera Sage

Hi,

Please refer to the official documentation with an example in here: https://docs.servicenow.com/bundle/madrid-platform-administration/page/administer/platform-events/ta...

Events are used to execute server side operations like sending notifications or executing any scripts asynchronously at the backend.

gs.eventQueue(event name, record, parm 1, parm 2) is used initiate an event calls, It has following parameters to passed in it: Event name, Current object of record, Parmeter 1 to pass, Parameter 2 to pass. It can be called in any server side scripts like business rules, workflow, script includes etc

Thanks!

Chander Bhusha1
Tera Guru

Hi Elizabeth,

gs.eventqueue is used to trigger an event.This is used in server side.

eventQueue(String name, Object glideRecord, String parm1, String parm2, String queue)

Parameter(s):

NameTypeDescription
nameStringName of the event being queued.
glideRecordObjectGlideRecord object, such as "current".
parm1String(Optional) Saved with the instance if specified.
parm2String(Optional) Saved with the instance if specified.
queueStringName of the queue.

 

The first parameter is event name and this is defined in the event-> Registry.

 

Please mark your response helpful or correct.

 

Thanks,

CB

 

Ramesh Lohar
Kilo Guru

The gs.eventQueue is a method in ServiceNow that is used to fire an event. This method is typically used in server-side scripting.

Here's a summary of its usage:

- The gs.eventQueue method is used to trigger an event in ServiceNow.
- It is a server-side method, meaning it is used in server-side scripts like Business Rules, Script Includes, etc.
- The syntax for using gs.eventQueue is: gs.eventQueue(String eventName, GlideRecord gr, String parm1, String parm2)
- eventName: The name of the event to be fired.
- gr: The GlideRecord of the record that the event is associated with.
- parm1 and parm2: Optional parameters that can be passed to the event.
- The event that is triggered by gs.eventQueue can be handled by an Event Script or a Notification.
- This method is asynchronous, meaning the script will continue to run without waiting for the event to complete.

Here's a sample code snippet:

javascript
var gr = new GlideRecord('incident');
gr.get('incident_number', 'INC0010001');
gs.eventQueue('custom.event', gr, 'parameter1', 'parameter2');


In this example, a custom event named 'custom.event' is fired for the incident with number 'INC0010001', and two parameters 'parameter1' and 'parameter2' are passed to the event.


nowKB.com