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

Does the event gets processed?


not sure...here's the record of the event, under "Processed" it says (empty)...so maybe not?



find_real_file.png


Have you register the event change.notification ?



Please have a look at the following link:



https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/administer/platform-events/task...


In your personal instance, you can navigate to System Properties->Email Properties and activate Email Sending and in 'Send All email to test email address', you can mention your email accounts.



find_real_file.png



Also go to Administration->Email Accounts and check if you have the POP3 and SMTP email accounts.



find_real_file.png



And check if you have events.process 1 in your scheduled jobs.


find_real_file.png



If not you have to create these email accounts and export the schedulers from a different instance and import it to your personal instance.


I didnt have these, so I had to create them



Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,


I actually went ahead and developed this in our company DEV instance and it's working perfectly...thanks!



Patrick