Mail notification using event queue

Alon Grod
Tera Expert

Hi,

I have a requirement to send an email notification to all assignment group's users of the child incidents when the parent incident is closed.

I created a Business rule on the incident table that trigger when state changes to close. then I go and check if this incident has child incidents with assignment group field is not empty. If yes, I know that I need to use the command:
gs.eventQueue();

 

what should I pass inside () ?

In addition, when creating the notifcation do I need to populate something in the 'Who will receive' Tab or not because I will specify the it inside the gs.queue?

1 ACCEPTED SOLUTION

Vrushali  Kolte
Mega Sage

Hello @Alon Grod ,

 

gs.eventQueue() takes five parameter and one of them is optional.

 

 

 

gs.eventQueue('event_name','glide_record_object',parm1,parm2, 'queue_name');

//#5 is optional

 

 

If you already know to whom you want to send notification then, you can directly pass the mail_id of that group in #parm1 and set the receiver as EVENT PARM  1 or you can select the group in the who will receive it tab as follows -

 

VrushaliKolte_0-1721639148712.png

VrushaliKolte_1-1721639153477.png

 

If my answer solves your issue, please mark it as Accepted✔️ and Helpful👍!

View solution in original post

5 REPLIES 5

Robbie
Kilo Patron
Kilo Patron

Hi @Alon Grod,

 

You won't get much better advice than from the man himself, @Chuck Tomasi. Check out his video which walks you through how and where to use gs.eventQueue().

 

High level steps:

- Create the event

- Call the event using gs.eventQueue() in a Business Rule as you've explained

- Set up a Notification which is triggered from said event

 

Chuck goes over it in the below link.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

 

https://www.youtube.com/watch?v=jXkGt4iJsnY

System events are a powerful way to run your business logic in the background. Watch this episode to learn what system events are, how to use existing events, and create your own to drive your process in the background. Episode topics include: * System events explained * Introduction to ...

Amit Pandey
Kilo Sage

Hi @Alon Grod 

 

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

 

Regards,

Amit

Nicholas_Gann
Mega Guru

Notifications triggered from events are still associated with a record in the same way that condition based notifications are, so you can specify the recipients using 'Users/Groups in fields' like you usually would


I've not watched the youtube video that's been added as a response so this will likely do into more detail but the second argument in gs.eventQueue([event name],[this one]) is the GlideRecord object of the record that the event relates to but there are 3 additional optional arguments that can be added

 

Depending on where your Business Rule triggered event is located:

- On the parent incident (as you've mentioned above), the GlideRecord object would need to be each of the child incidents, so you would effectively be triggering this event multiple times based on the number of child incidents

- On the child incident, you could pass in current directly

 

This is documented on GlideSystem - Global (servicenow.com) (Search for eventqueue)

SN_Learn
Kilo Patron
Kilo Patron

Hi @Alon Grod ,

 

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.
gs.eventQueue('name.of.event', current, parm1, parm2);

 

Breakdown:

'name.of.event' will be the event name created under Event > registry [sysevent_register].

current is the GlideRecord object

In parm1 or parm2 you can pass recipient(s)

 

Now, in the notification, under when to send, you will select 'fired by event' and provide the correct event name which you created in sysevent_register table in above steps. Once that is done, navigate to 'Who will receive' there will be 2 checkbox named 'Event parm 1 contains recipient' and 'Event parm 2 contains recipient' so based on the parameter you paased in gs.eventQueue() in business rule, you have to check this box in notification.

 

SN_Learn_0-1721638225378.png

 

Check the post which you give you more insights: 

Video: Community Live Stream - API Adventures - gs.eventQueue 

The Power of #ServiceNow System Events 

ServiceNow Events | ServiceNow trigger Email notification from Event 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.