Scheduled Job working only if i trigger manually using "Execute Now", Automatically based on time provided it was not working.

Swaroop10
Giga Contributor

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.

1 ACCEPTED SOLUTION

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

View solution in original post

13 REPLIES 13

Hello Ankur,

I have validated, it was getting failed because one of the schedule is validating Business hours, so i have removed that schedule and ran the script and it returned "True".

But in my Scheduled job i have removed the condition completely and waiting, still it was not triggering. I have kept logs as well, when i did manually it was working but when i am waiting for automatic trigger it was not working as expected.

 

 

Thanks & Regards,

S.Swaroop.

Hi Swaroop,

job is set to run daily; as said by Asif please use repeat and then select 30 mins then it will run every 30 mins.

Try that

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

It worked perfectly, Thank you very much.

 

 

Thanks & Regards,

S.Swaroop.

HI Ankur,

Even i'm facing the same issue with a scheduled job......it works when manually executed but not triggering automatically.

I do not see the Repeat option in the RUN dropdown, it is available only in Lists view. Can you please guide me further on this.

find_real_file.png