schedule job script not executing, the script works in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 06:22 AM
Hi Team,
I am facing this unusual issue where a schedule job does not trigger for a schedule job, however the same works when run from background script.
The condition is something like this
var chg = new GlideRecord('change_request');
chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=0');
//chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=0^assignment_group.nameSTARTSWITHservicenow^number=CHG0041873');
chg.query(); gs.log('chg 001');
while(chg.next()){
gs.log('chg 002');
chg.state="4";
chg.close_code= 'Auto-terminated in review';
chg.close_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.';
chg.work_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.';
chg.update();
gs.log('chg 003' +chg.number);
}
This although is supposed to run everyday at 23:50 , but there is no trace in the sys_trigger table.
Also, please note when i force execute it , the logs can be seen but not the action, i.e. change does not updates/closes.
Btw, i have similar scheduled scripts running for the condition, all running in global application
var chg = new GlideRecord('change_request');
chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=-2');
chg.query();
while(chg.next()){
chg.state=4;
chg.close_code= 'Auto-terminated in scheduled';
chg.close_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.';
chg.work_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.';
chg.update();
}
Can you please point me towards something useful?
Regards,
Shariq
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 06:33 AM
Hi Shariq,
I can offer two suggestions. First, add a diagnostic to the log by adding a getRowCount() after you do the chg.query() to confirm that you are actually getting data returned.
The other is that state is an integer. In the script that is not working, you are assigning a string while in the one that works you are assigning an integer.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 09:17 PM
Hi John,
As you already see, the logs are are coming correctly. The state field is set to a string variable now, earlier it was set as integer, and yet it didnt work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 09:32 PM
Hi Shariq,
Did you try check script shared in my previous comment and try to check rowCount
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 04:39 AM
Have you confirmed that your query is getting results. You can also try using .setDisplayValue() to assign the state and see if that works.
:{)
:{)
Helpful and Correct tags are appreciated and help others to find information faster