- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:00 PM
Hello,
I am having a schedule job which will run every 30Min and Daily. When i manually use "Execute Now" UI Action, it was working as expected but only when i manually did, it is working but it was working automatically based on the time(30Min) provided. Below is the condition and script i am using in Scheduled job.
Condition -
var answer = false;
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981"); - For validating Business hours
var w = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714"); - For Validating US Holidays
var gdt = new GlideDateTime();
if(gdt.getDayOfWeek() >= 1 || gdt.getDayOfWeek() <= 5){
if(s.isInSchedule(gdt)&&!w.isInSchedule(gdt)){
answer = true;
}
}
Script -
var gr = new GlideRecord("incident");
gr.addEncodedQuery('sys_created_onRELATIVELT@minute@ago@40');
gr.addQuery('assigned_to',"");
gr.addQuery('active',true);
gr.query();
while(gr.next())
{
gs.eventQueue("trigger.incident.unassigned",gr);
gr.u_ntfctn_flag = true;
gr.update();
}
I cant able to figure out why it working as expected when i did it manually but not triggering automatically after every 30Min.
Please suggest me if i did wrong anywhere in the script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2020 12:24 AM
Hi Swaroop,
As per the screenshot it is scheduled to run daily once at 05.
Instead of Daily, select repeat and then select 30 mins then it will run every 30 mins.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:21 PM
Hi,
Can you add some logs in the script and check. May be the script is running but not entering into your while loop.
Also, when you run this i assume an incident existed which is less than 40 minutes ago, where as when schedule script runs, is there any incident which was created in last 40 minutes?
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:30 PM
Hello Asif,
But when i did "Execute Now" manually, it is working as expected, But not triggering automatically after every 30min.
Yes, there are tickets which was created 5hours ago.
Thanks & Regards,
S.Swaroop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:39 PM
Hello Swaroop,
To understand whether script is not triggering or giving an error, you need to debug. Place a log in the 1st line of your script and check if that line comes in the log after 30 mins.
If you don't get that, then it means there is no issue with your script. May be the conditions are failing. Remove the conditions and check again.
If you get 1st line, then check if there is any error that is coming.
Also, if you run now manually, then all incidents might be already updated. So after 30 mins, even if your script runs, i don't think any update will happen. Check if the event is triggered or not?
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2020 12:15 AM
Hello Asif,
When i first ran the script with Log in the first line of the script and did "Execute Now" it returned the log.
Second time i have removed the condition completely and waiting for automatic trigger but it is not triggering the schedule job.
Third time when i Triggered manually without condition, then script and log got triggered. I don't know why it is working only when i used "Execute Now" UI Action.
Thanks & Regards,
S.Swaroop.