
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2018 10:11 PM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2018 01:40 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2018 11:49 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2018 01:40 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 03:49 AM
Hi Rakhesh,
Please Mark it as correct if it solves your issue.
Thank you,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2018 09:53 PM
Hi Ashutosh,
We are also facing the same kind of issue.If you provide the issue that should be very helpful for us.