Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

SLAs Not Stopping After Work request is closed

Afrin12
Tera Contributor

SLAs Not Stopping After Work Request Auto-Closure

 

Afrin12_0-1741622838552.png

Scheduled job runs every day to close the work request automatically,
Script:

function ProcWorkOrdAuto() {
var wrk = new GlideRecord('u_work_order');
wrk.addEncodedQuery('state=9^ORstate=3^NQstate=4^sys_updated_onONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()');
wrk.query();

while (wrk.next()) {
var sla = new GlideRecord('task_sla');
sla.addEncodedQuery("task=" + wrk.sys_id + "^sla=a95fe6e9dbfd10905dc552625b96190e^active=true");
sla.query();

while (sla.next()) {
var seconds = sla.u_idb_business_duration.getGlideObject().getNumericValue() / 1000;
if (seconds >= 259200) { // 3 days
wrk.state = "4";
wrk.work_notes = "Work Request automatically closed by system.";
wrk.active = false;
wrk.closed_at = gs.nowDateTime();
wrk.update();
}

if (wrk.state == '4') {
SLACalculatorNG.calculateSLA(wrk, false);
}
}
}
}


But Sla is in progress

Afrin12_2-1741623054185.png

 



Afrin12_1-1741623025966.png

Any suggestions on what might be missing? Thanks in Advance.

 

 

12 REPLIES 12

Hi @Afrin12 

 

Could you please try to repair the SLA once and then check also try to remove the condition on complete, i am assuming this is causing the issue.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG 
I have tried but still having the issue

Did you try to remove the complete state condition and then try to repair SLA.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

yes

It should work since everything looks good on my end. Also, are the start and pause conditions functioning properly? Try creating another SLA/OLA in the same table and check if it's working. It seems like there might be a cache issue.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************