Scheduled job condition not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 06:35 AM
I wonder if anyone can help with this. I have a scheduled job that I want to run on the 1st of each quarter. I've created a condition script that looks like this:
var answer = false;
var now = new Date();
var month = now.getMonth();
if (month == 0 || month == 3 || month == 6 || month == 9) {
answer = true;
}
answer;
When the above is run as a background script it works. I can output answer at the end and see that it is correctly calculated.
However with the scheduled job, which was meant to run on 1st October, the job didn't trigger (it's meant to create a handful of requests - these haven't been created).
I can't find anything in the logs to say there was a problem. To be honest the only way I know the job triggered is because the next action is 1st November - It's a monthly job that runs on the 1st of each month).
I've checked the script that it runs, and if I execute it manually it works, so I know there isn't a problem with the script. It's just the condition that doesn't appear to be working.
Is there anyone that might have an inkling as to what might be wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 06:40 AM
Hi @spike
Try this code
var gdt = new GlideDateTime();
var month = gdt.getMonth();
if (month == 0 || month == 3 || month == 6 || month == 9) {
answer = true;
}
answer;
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 06:42 AM
Conditional scripts run in a sandbox and so the Glide System isn't available. That's why I've had to use vanilla javascript. This article talks about it and the code I'm using is based on their workaround:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0827366
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:56 AM
Hi @spike
Try this
var now = new Date();
var month = now.getMonthUTC();
if (month == 0 || month == 3 || month == 6 || month == 9) {
answer = true;
}
else{
answer = false;
}
Please mark my answer correct/helpful if it resolved your query