How can i auto close the SLA ?

Rakhesh
Kilo Guru

HI Every One,

We have an issue i.e., The SLA is attached when the status is 'Resourcing in progress' and the duration is 3 days. And the issue is the 5th day of the SLA will be Auto Close.We don't know how can be done this Issue.Can anyone knows please help me to how can i achieve this.

Regards,

Rakhesh.

1 ACCEPTED SOLUTION

HI Guys,



Final Script:



var schedule = new GlideSchedule();


schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule


schedule.setTimeZone(gs.getUserTimeZone());




//Get the current date/time in correct format for duration calculation


var startDate = new GlideDateTime();


startDate.setDisplayValue(gs.nowDateTime());


gs.print('Actual '+startDate);




var getSla = new GlideRecord('task_sla');


getSla.addQuery('stage','in_progress');


getSla.addQuery('has_breached',true);


//getSla.addQuery('sys_id','b2356ff6db230300e77dd450cf9619a6');


getSla.query();


while(getSla.next())


{


//Query for resolved incident records


var gr = new GlideRecord('incident');


//gr.addQuery('state', 6);


gr.addQuery('sys_id',getSla.task);


gr.query();


while(gr.next()){


var endDate = new GlideDateTime();


endDate.setDisplayValue(gr.opened_at);


gs.log(endDate);


gs.log('Start '+getSla.start_time.getGlideObject());


//Close any records that have not been updated in 'pn' number of days


//Date difference calculated based on specified schedule


var duration = schedule.duration(endDate,startDate).getDayPart();


gs.log('Difference '+duration);


if(dif >= 5){


                gr.state = 7;


                gr.active = false;


                //gr.comments = 'Incident automatically closed after ' + pn + ' hours in the Resolved state.';


                gr.update();


          }


}


}



Thank you,


Ashutosh


View solution in original post

13 REPLIES 13

Hi Rakhesh,



This is the best script for you, see below link.


https://www.servicenowguru.com/scripting/business-rules-scripting/calendar-based-incident-autoclose/



Thank you,


Ashutosh Munot



Please Mark helpful, Correct and Endorse, as per impact.


HI Guys,



Final Script:



var schedule = new GlideSchedule();


schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule


schedule.setTimeZone(gs.getUserTimeZone());




//Get the current date/time in correct format for duration calculation


var startDate = new GlideDateTime();


startDate.setDisplayValue(gs.nowDateTime());


gs.print('Actual '+startDate);




var getSla = new GlideRecord('task_sla');


getSla.addQuery('stage','in_progress');


getSla.addQuery('has_breached',true);


//getSla.addQuery('sys_id','b2356ff6db230300e77dd450cf9619a6');


getSla.query();


while(getSla.next())


{


//Query for resolved incident records


var gr = new GlideRecord('incident');


//gr.addQuery('state', 6);


gr.addQuery('sys_id',getSla.task);


gr.query();


while(gr.next()){


var endDate = new GlideDateTime();


endDate.setDisplayValue(gr.opened_at);


gs.log(endDate);


gs.log('Start '+getSla.start_time.getGlideObject());


//Close any records that have not been updated in 'pn' number of days


//Date difference calculated based on specified schedule


var duration = schedule.duration(endDate,startDate).getDayPart();


gs.log('Difference '+duration);


if(dif >= 5){


                gr.state = 7;


                gr.active = false;


                //gr.comments = 'Incident automatically closed after ' + pn + ' hours in the Resolved state.';


                gr.update();


          }


}


}



Thank you,


Ashutosh


Hi Rakhesh,



Please Mark it as correct if it solves your issue.





Thank you,
Ashutosh


Hi Ashutosh,



We are also facing the same kind of issue.If you provide the issue that should be very helpful for us.