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-11-2025 12:16 AM - edited 03-11-2025 12:17 AM
start and pause conditions are working properly. I will try again.
Thank you very much for your quick response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 12:25 AM
Hi @Afrin12,
If you want the SLA to stop when the state is "Closed," consider:
Removing the second condition (State is not Completed) if it conflicts with your first condition and do some changes on your script in Schedule job.
function ProcWorkOrdAuto() {
var wrk = new GlideRecord('u_work_order');
wrk.addEncodedQuery('state=9^ORstate=3^NQstate=4^sys_updated_on>=javascript:gs.beginningOfThisWeek()^sys_updated_on<=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; // Assuming state is an integer
wrk.work_notes = "Work Request automatically closed by system.";
wrk.active = false;
wrk.closed_at = gs.nowDateTime();
wrk.update();
break; // Exit the inner loop after closing the work request
}
}
// Call SLA calculation only if the work request is closed
if (wrk.state == 4) {
SLACalculatorNG.calculateSLA(wrk, false);
}
}
}
If my response helped you, please accept the solution and mark it as helpful.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 01:31 AM
Thank you , I will try this way