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

Medi C
Giga Sage

@Afrin12 
You do not need to query the task sla table.

SLA would stop when the stopping conditions are met.

 

please adjust your script so that your schedule job is only updating the “work request” to complete or closed states.

 

please check the conditions on Stop debugging.

there is State “is not” Complete. Shouldn’t it be State is Complete instead ?


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Afrin12
Tera Contributor

SLA should start when Work request is completed and it will stop when the work request is closed. But the SLA is still running when work request is closed too.

Hi @Afrin12 

 

What is the stop condition? Any screenshot please?

*************************************************************************************************************
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

Afrin12_0-1741674998763.png