I have a requirement to create SLA records for closed RITM's that never had an SLA at the time of closure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 03:03 PM
I have a bunch of RITMs that were created and closed before we had RITM SLA's implemented. Is there a script that would go through each, generating the SLA record?
Here's a script i had partly put together from a similar reply here
var gr = new GlideRecord('sc_req_item');
var strQuery = 'active=false';
strQuery = strQuery + '^item=<item name>'; //catalog item name
gr.addEncodedQuery(strQuery);
gr.query();
while (gr.next()) {
var created = gr.sys_created_on;
var actual_end = gr.work_end;
var grSLA = new GlideRecord('task_sla');
grSLA.newRecord();
grSLA.task = gr.getUniqueValue();
grSLA.sla = '<sys_id>'; //sys ID of the SLA i'd like to run here
grSLA.schedule = '<sys_id>'; //sys ID of the schedule i'd like to run here
grSLA.start_time = created;
grSLA.end_time = actual_end;
grSLA.insert();
var task_sla = new GlideRecord('task_sla');
task_sla.get(grSLA.getUniqueValue());
SLACalculatorNG.calculateSLA(task_sla, false, task_sla.end_time);
}
- Labels:
-
Service Level Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 10:31 AM
This edited code worked for me part of the way. It set the start time at the correct time, i edited a line to get it to set the stop time correctly too, the stage of the SLA i forced to 'Complete' (although that text is in blue?).
The total calculated time however is up until the day the script runs and not when the RITM was completed
var gr = new GlideRecord('sc_req_item');
var strQuery = 'active=false';
strQuery = strQuery + '^numberLIKERITM0028043'; //catalog item name
gr.addEncodedQuery(strQuery);
gr.query();
while (gr.next()) {
var created = gr.sys_created_on;
var actual_end = gr.closed_at;
var grSLA = new GlideRecord('task_sla');
grSLA.newRecord();
grSLA.task = gr.getUniqueValue();
grSLA.sla = '89fb7bf21b05c550595042e58d4bcbd0'; //sys ID of the SLA i'd like to run here
grSLA.schedule = '01b228b81b162c10595042e58d4bcb61'; //sys ID of the schedule i'd like to run here
grSLA.start_time = created;
grSLA.end_time = actual_end;
grSLA.stage = 'Completed';
var newSlaRecord = grSLA.insert();
new SLACalculatorNG().calculateSLA(newSlaRecord, false, grSLA.end_time);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 08:49 PM
Please give the proper back-end stage value in the script, I believe you gave the wrong one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 08:18 AM
I checked the back-end stage and it was a matter of lower case 'c' 🙂 Thank you!
Do we know why the calculation is not happening correctly? It is still calculating elapsed times from the created date/start time to the date i'm running the script, instead of 'stop time'
I removed the line below, and got the same result, so i don't think this line is even processing
new SLACalculatorNG().calculateSLA(newSlaRecord, true, grSLA.end_time);
I appreciate all your assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 09:52 PM
Could you try this?
SLACalculatorNG.calculateSLA(newSlaRecord, false, grSLA.end_time);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 08:48 PM