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

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI Rakesh,



So you want to close this SLA after 5 days of it attachment.



Please clarify. If so then i have script with me/



Thank you,
Ashutosh


Hi Ashutosh,



Thanks for responding to my issue. Yes we need to auto close the SLA after 5 days.


HI Rakhesh,



Do you want to exclude weekends or not?



Thank you,


Ashutosh



Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Yes Ashutosh,We want to exclude weekends.