- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 12:08 PM
Forgive me I am learning
I have submitted a scheduled job, when I click 'execute now' the job does not run. I cannot see an entry in event logs.
If I copy the script from the scheduled job and run it in background scripts - it inserts the rows in event logs and (the rest of the processing) works fine.
var res = new GlideRecord('x_hotel_reservation');
res.addQuery('departure', gs.now());
res.addNotNullQuery('room');
res.query();
while(res.next()){
gs.eventQueue('x_hotel.room.reservation_end', res.room.getRefRecord());
}
I can only assume something is wrong with the scheduled job I am trying to run.
any help directing me to a solution would be welcomed.
Many thanks for your time.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 01:18 PM
Hi,
Since this is a scoped application, it seems your scheduled job is unable to create new records in the sysevent table but when you run it from a background script, the scope is global and you are getting access to add records in the sysevent table. I suggest you try configuring table application access by allowing other application scopes to create records in sysevent table. Please check and let me know
Application Access Settings - ServiceNow Wiki
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 12:39 PM
Hello Laurence,
The problem is gs.now() returns GMT. It runs well in background script but seems not to work properly in other places.
You can modify the scripting as following:
var gdt = new GlideDateTime();
gs.log(gdt.getDate());
var res = new GlideRecord('x_hotel_reservation');
res.addQuery('departure', gdt.getDate());
res.addNotNullQuery('room');
res.query();
while(res.next()){
gs.eventQueue('x_hotel.room.reservation_end', res.room.getRefRecord());
}
Hope this helps.
Please hit Like or mark Helpful or Correct based on the impact.
Thanks,
Rajshekhar Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 01:06 PM
Thank you. I became very excited that a solution was close but...
I have the same effect - the 'execute now' does nothing.
I pasted your script into background scripts and it worked fine as the previous script.
Any further thoughts? I had been testing with different date formats (nowNoTZ()) but with no working effect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 01:18 PM
Hi,
Since this is a scoped application, it seems your scheduled job is unable to create new records in the sysevent table but when you run it from a background script, the scope is global and you are getting access to add records in the sysevent table. I suggest you try configuring table application access by allowing other application scopes to create records in sysevent table. Please check and let me know
Application Access Settings - ServiceNow Wiki
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 01:46 PM
Thank you, great advice - I had been considering this because the script will not run (in background script) if I change the scope from global.
I followed your advice by changing the 'can read' and 'can create' flags (testing at each change) for the sysevent, sysauto and then sys_trigger tables.
The schedule will still not add an event log and nothing gets processed.
Further advice welcome - but you have given me a link to read and digest which i will do, since learning more can only help.
Thank you once more.
