Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

scheduled job not running

l4urence
Mega Contributor

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.

1 ACCEPTED SOLUTION

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



find_real_file.png



Application Access Settings - ServiceNow Wiki



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

7 REPLIES 7

Rajshekhar Pau1
Kilo Guru

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


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.


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



find_real_file.png



Application Access Settings - ServiceNow Wiki



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


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.