Scheduled Jobs execution: how to execute script?

stryker129
Mega Guru

Hi guys,

I wrote a script for Scheduled Job which runs on demand:

When I click "Execute Now" button - I expect to see either info message or console log.

But it shows me nothing.

Debugger also doesn't stop on break-points.

Please advise where I am wrong?

Thanks.

var gr = new GlideRecord('x_11111_notes_customer_reminders');

gs.addInfoMessage("test");

console.log('test');

gr.addQuery('status', 'Scheduled');

while (gr.next()) {

      var customer = {

              name: gr.getDisplayValue('customer'),

              id: gr.customer

      };

      gs.addInfoMessage("customer", customer);

}

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Scheduled jobs operate in the background via worker so you won't be able to see any foreground messages in the console or on the screen.   You can use gs.log() to put a message in the Logs and view that way but again you won't be able to see them in foreground.


View solution in original post

3 REPLIES 3

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Scheduled jobs operate in the background via worker so you won't be able to see any foreground messages in the console or on the screen.   You can use gs.log() to put a message in the Logs and view that way but again you won't be able to see them in foreground.


Harsh Vardhan
Giga Patron

Hi Ivan,



agreed with michael.ritchie


In sys_trigger table there is a field Run count which gets incremented by one whenever schedule job get executed. you can check that also



Thanks,


Harshvardhan


codycotulla
Tera Guru

Hi,

I've published a short article about how you can test Scheduled Jobs with the Script Debugger.

If you are interested, take a look at it here.

Hope you find it useful.

Thanks,

Cody