SLAs Not Stopping After Work request is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 09:15 AM
SLAs Not Stopping After Work Request Auto-Closure
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
Any suggestions on what might be missing? Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 09:37 AM
@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 ?
Thanks & Best regards,
Medi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 11:09 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 11:27 PM
Hi @Afrin12
What is the stop condition? Any screenshot please?
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/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 11:36 PM
Hi
