- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 01:46 PM
Hi all,
I'm building a scheduled job to fire an event, and am using the following script, however in the line in BOLD the script is giving me the error in the screen shot...it's not firing the event properly and my notification that is triggered off that event is not sending. Error in my script? thanks!
var sd = new GlideRecord('change_request');
sd.addQuery('state','-5');
sd.query();
while(sd.next()) {
if(gs.dateDiff(gs.nowDateTime(),sd.end_date.getDisplayValue(), true) < 0)
gs.eventQueue('change.notification', sd.number, sd); //something wrong here?
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:07 PM
Your second parameter needs to be a record. See this Wiki article for details:
3.1.1 Input Fields
Parameters:
- Name of the event being queued.
- A GlideRecord object, such as "current".
- An optional parameter, saved with the instance if specified.
- A second optional parameter, saved with the instance if specified.
- An event queue to add the event to.
So the following should work:
gs.eventQueue('change.notification', sd, sd.number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:07 PM
Your second parameter needs to be a record. See this Wiki article for details:
3.1.1 Input Fields
Parameters:
- Name of the event being queued.
- A GlideRecord object, such as "current".
- An optional parameter, saved with the instance if specified.
- A second optional parameter, saved with the instance if specified.
- An event queue to add the event to.
So the following should work:
gs.eventQueue('change.notification', sd, sd.number);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:18 PM
Hi Patrick,
Yes, I believe the following line is not correct:
gs.eventQueue('change.notification', sd.number, sd)
As you are calling gs.eventQueue from a schedule job you should pass the GlideRecord in the Record parameter (2nd parameter), and not sd.number.
I would suggest the following instead:
gs.eventQueue('change.notification', sd, sd.number)
You can pass a 4th parameter if you think it is necessary, otherwise it should work like that.
Please have a look at the following example, for more information:
http://wiki.servicenow.com/index.php?title=Events_and_Email_Notification#Building_a_Script
Let me know how it goes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:26 PM
Thanks Michael and Marcio,
so I needed to reverse the 2nd and 3rd parameters in that line.
Does this actually pass this info through the event all the way to the notification somehow? I'm guessing yes...so that the notification can include as much info about the specific change record causing the event to fire.
Am I on the right track?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:28 PM
Yes it does and in your notification on the last tab you can select fields you want to include, basically putting them into ${field_name} type format. You can even dot walk from the change to its related records too.