- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 07:02 AM
There are some problem records whose slas are running since there are no stop conditions met. please help me with a script to glide those problem records and update their SLAs status to cancel.
Thank You in advance pradeepksharma
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:06 AM
Hi Raviteja,
This can quite easily be achieved within a background script. I've given you the framework to use and build from below to help you update these records.
One thing you'll need to be careful and aware of is how to build the query out to only select the records you require (ie how do you identify the specific problem records you want to update? What sort of number are we talking about? Is there any particular criteria or conditions can you use to select the Problem records, or are you going to pass the absolute number values?
This script will identify the Problem SLA definition(s) that don't have a stop condition, and then identify the 'In progress' SLA records against the (no stop condition) SLA definition and update the records to 'Cancelled' as required.
You may want to tweak the query criteria if you need any other selection criteria. As always, please be sure to test on Dev first of course but this should do the trick.
Thanks, Robbie
Please mark this as correct and helpful via your post link (glide task sla and update status to cancel, please help with script ) to help close out open questions and help aid others with the same question.
Background script:
//Find SLA Definition(s) (on Problem table) which has/have an empty stop condition
var slaDefGR = new GlideRecord('contract_sla');
slaDefGR.addQuery('collection', 'Incident');
slaDefGR.addQuery('stop_condition', '');
slaDefGR.query();
while(slaDefGR.next()){
//Loop through In Progress SLA's records running against above defined Problem SLA def with no stop condition
var taskSLAsGR = new GlideRecord('task_sla');
taskSLAsGR.addQuery('sla', slaDefGR.sys_id);
taskSLAsGR.addQuery('stage', 'in_progress');
taskSLAsGR.query();
while(taskSLAsGR.next()){
gs.log('BEFORE UPDATE - Task is ' + taskSLAsGR.task.number + ' SLA Defintion: ' + taskSLAsGR.sla.name + ' Current Status: ' + taskSLAsGR.stage);
//You may want to use an if clause for any further selection criteria if required but this has been commented out for now.
//if(taskSLAsGR.sla.name == 'XXXX'){
taskSLAsGR.stage = 'cancelled'
taskSLAsGR.setWorkflow(false);
taskSLAsGR.autoSysFields(false);
taskSLAsGR.update();
gs.log('AFTER UPDATE - Task is ' + taskSLAsGR.task.number + ' SLA Defintion: ' + taskSLAsGR.sla.name + ' Current Status: ' + taskSLAsGR.stage);
//}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 10:22 AM
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 05:12 AM
Hi,
If I use the same script in business rule, it is not working......If the code is working in background script then it should work in business rule as well, I don't know why it is not working for me could you please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 10:22 AM
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 10:38 AM
Hi Raviteja,
So this is where I advised about being mindful of how to build the query out to only include the records you want to update.
Is there any criteria we can use such as date range for example to select the particular Problem records?
You can also just explicitly update only the Problem numbers you require as shown below (assuming this isn't a large number of Problem records):
Update the following from:
//Loop through In Progress SLA's records running against above defined Problem SLA def with no stop condition
var taskSLAsGR = new GlideRecord('task_sla');
taskSLAsGR.addQuery('sla', slaDefGR.sys_id);
taskSLAsGR.addQuery('stage', 'in_progress');
taskSLAsGR.query();
while(taskSLAsGR.next()){
to
//Loop through In Progress SLA's records running against above defined Problem SLA def with no stop condition
// comma delimiter used to pass in the number required to update
var string='task.numberINPRB0000003,PRB0000005';
var taskSLAsGR = new GlideRecord('task_sla');
taskSLAsGR.addQuery('sla', slaDefGR.sys_id);
taskSLAsGR.addQuery('stage', 'in_progress');
taskSLAsGR.addEncodedQuery(string);
taskSLAsGR.query();
while(taskSLAsGR.next()){
Thanks,
Robbie