The CreatorCon Call for Content is officially open! Get started here.

Any ideas on how to script on mass repair SLA's

sgoud
Kilo Explorer

Hi Guys ,

I got a requirement to design a script for mass repair of SLA's ? i couldn't find anything regarding that .. could you help me with any lead ?

Thanks in advance ,

Sanjay

10 REPLIES 10

Thanks.   Would you be able to help me with the script?



Regards,



Robin


Robin,



I don't use the 'Repair SLA' frequently so I wasn't aware of this but ServiceNow has a UI Action (Repair all filtered SLAs) that should help you.



  - Go to task_sla.list and then filter the list to only the SLA's that you want to repair


  - Scroll to the bottom of your list and you should see the UI Action


Hi Jacob,



Unfortunately the UI Action can only be run against a list of records, so it's limited to 1000 at a time (I have 13k+ to update so would take a while).   I was hoping to find a way to bulk update from a Glide Query.


jacob_benker
Tera Expert

Alekhya,



The SLA Repair runs against records in the task_sla table.


So I would need to know more about what about your SLAs are triggering the need to run repair.


If you can use a date field on the form then I would do that.


You can do 'created' in last 24 hours, 'breach time' in last 24 hours, or whatever is triggering the repair need.


markledwich
Giga Contributor

Hi Sanjay,



I had exactly the same question and I worked it out. (I am on Istanbul)



1. Go to System Definition > Script Includes and search for RepairSLA. This is a very useful class to help script what you are doing. Keep that handy to refer to while making your script


2. Create a new Fix script that uses this include. Below is one that i wrote,


      - you should change the query with one that you want and that should be the only change.


        - On my system it took a few minutes to update about 1k records.


        - This is my first script so i'm sure its got problems. But its a start.



var gr =   new GlideRecord('incident');


gr.addQuery("numberSTARTSWITHMINC_");


gr.query();


gs.info("Number of incidents to update " + gr.getRowCount());




var sla = new SLARepair();


while(gr.next()){


  var sysId = gr.getValue('sys_id');


  gs.info("Updating incident " + sysId);


  sla.repairBySysId(sysId, "incident");


}



3. Run in the background


4. Open Service Level management > repair Logs > All repairs and you can see the repair items as they are executed