gs.eventQueue not firing properly

patricklatella
Mega Sage

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?

}

find_real_file.png

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Your second parameter needs to be a record.   See this Wiki article for details:


GlideSystem - ServiceNow Wiki



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);


View solution in original post

19 REPLIES 19

patricklatella
Mega Sage

I'm just clicking "Execute Now" on the schedule job for testing, and that is firing the event properly.



It's in the test instance, so not sure how events are processed.


patricklatella
Mega Sage

sorry, to clarify it's in my developer sandbox instance


Did it work with Execute now() UI Action?


it triggers the event, but the event does not trigger the notification