Australia upgrade broke script logic in Scheduled Jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
We had a need to run certain scheduled jobs on a specific schedule that wasn't supported out of the box. To that end we came up with a simple script to meet our requirements.
var run = false;
var today = new Date();
var weekday = today.getDay();
if (weekday > 0 && weekday < 6)
{
run = true;
}
else
{
run = false;
}
Once we upgraded to Australia, this is no longer working for us. I have opened a case with ServiceNow support regarding this, and they came back and said the Run cannot be executed because it has no meaning outside of the script however it worked in Yokohama. Anyone else encountered this, or have a solution? They are pointing me to a KB article about running Flows on a specific day of the week, but what I was doing existed only in scheduled jobs and had no flows involved. Am I going to have to build a flow now to make this work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ChrisWing ,
Can you use a self-invoking method and return the run variable at the end of your script?
I had a similar requirement previously, where the scheduled job needed to run only on weekdays before the Australia release. I have verified the scheduled job execution, and it is working as expected—the job is not running on weekends after the instance was upgraded to the Australia release.
Please refer to the script below.
(function() {
var answer = false;
// For testing purposes, pass a specific date/time to GlideDateTime().
// Example: new GlideDateTime('2026-08-09 05:21:33');
var now = new GlideDateTime();
// Check whether the current day is a weekday (Monday through Friday).
if (now.getDayOfWeekUTC() != 7 && now.getDayOfWeekUTC() != 6) {
answer = true;
} else {
gs.info(now + " is a weekend. Skipping Job.");
}
return answer;
})(); I hope this helps! If this resolves your issue, please consider marking this reply as Helpful or Accept as Solution.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
I tried your solution over the weekend, and it still created entries when it should not have, so this was not the solution. Pasting the copy of your script I used in case I am missing something.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @ChrisWing ,
The script is working correctly in my PDI, so I’m not sure why it is not working as expected in your instance.
As an alternative approach, you can change the Run field to Weekly and select the checkboxes for the days on which you want the Scheduled Job to run. This approach does not require any scripting.
Please refer to the screenshot below .
I hope this helps! If this resolves your issue, please consider marking this reply as Helpful or Accept as Solution.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Definitely the best option.
Is that new ? ...or maybe scheduling has better options in some places; where I worked had a script on discovery scheduled because we only wanted them to run certain days of the week - I don't believe we had that option ...and I can't' check that, PDI doesn't have discovery.
...but, in my mind, the original issue still stands - suppose we wanted to run a script every 5th day. That would be a different day of the week each time so we would be back at a scripted condition. If you have resources to follow up with Support, using the code written in the self-invoking way so it's consistent with OOTB code, then I would still do so as it's either a bug in general or an issue with your instance.