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

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

Hello Asif,

It worked perfectly, Thank you very much.

 

 

Thanks & Regards,

S.Swaroop.

Hi Swaroop,

As already suggested by Asif please add some logs in the condition and check if it is going inside and giving any error or not

What you can do is try running this script in background to check whether it returns true/false

gs.info(getValue());

function getValue(){
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;
}
}
return answer;

}

Regards
Ankur

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

Hello Ankur,

When i ran the script in Background it returned False.

 

 

Thanks & Regards,

S.Swaroop.

Hi Swaroop,

so it means it must be failing because of either of the schedule

please check for which one it is failing

Regards
Ankur

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