glide task sla and update status to cancel, please help with script

Raviteja K
Tera Expert

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

1 ACCEPTED SOLUTION

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);


        //}


  }


}


View solution in original post

8 REPLIES 8

shloke04
Kilo Patron

Hi,



You can update those records from backend using a Background script. Please find the same below:



var gr = new GlideRecord('task_sla');


var string='task.numberININC0000018,INC0000029';


gr.addEncodedQuery(string)


gr.query();


while(gr.next())


{


gr.setWorkflow(false);


gr.autoSysFields(false);


gr.stage= 'completed';


gr.update();


}



Note: In the above sample code in Line Number 2 "replace the Incident Number with your Problem Number". To be on a safer side while using Background scripts try this code first for a single Problem Number post which do it for rest of the records.



Hope this helps. Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

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);


        //}


  }


}


Thanks for the endorsement Anurag Tripathi - Appreciated


This is helpful, but the issue is all the problem records which are in_progress gets cancelled. We need to perform action only on specified problem records. Can you tweak this for me. Thanks a lot.