Auto closure of a case record after 7 business days from the date of resolved using scheduled jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 12:29 AM
Hi All,
I'm trying to auto close my case records after 7 business days from the date of resolved using schedule jobs.
Can you help me how i can achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 12:49 AM
for handling business days you will have to consider using schedule in your calculation
remember there might be already 1 OOB auto case closure functionality
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:31 AM
Hi @Ankur Bawiskar,
I have tried below script , but some how it is not working as expected in the schedule job
one more thing which i observed was when i run the same script in the background it's was working
Can you please check the script and let me know where exactly i was missing something.
Thanks in Advance.
function subDaysInSchedule(scheduleName, startDate, daysBack) {
var limitDaysBack = 100
//Get a schedule by name to calculate the check
var schedRec = new GlideRecord("cmn_schedule");
schedRec.get("name", scheduleName);
//Get date/time in correct format for duration calculation
var endDate = new GlideDateTime();
var startDateBeg = new GlideDateTime();
startDateBeg.setValue(startDate);
startDateBeg = startDateBeg.getLocalDate();
endDate.setValue(startDateBeg);
usrTZ = startDateBeg.getUserTimeZone();
var dc = new DurationCalculator();
dc.setTimeZone(usrTZ);
dc.setSchedule(schedRec.sys_id);
// Max 100 Days, just if loop does not find a slot in the schedule
var limitHoursBack = limitDaysBack * 8; // 9-Hours = 1-Business Day
for (var i = 0; i < limitHoursBack; i++) {
//Substract hour by hour
endDate.addSeconds(-3600); //1hour = 60sec * 60min
//Calculate Duration
var duration = dc.calcScheduleDuration(endDate, startDateBeg);
//If we went enough hours back, quit
if (duration / 32400 >= daysBack) { // 32400 Seconds = 9-Hours = 1-Business Day
break;
}
}
return endDate;
}
gs.info(new GlideDateTime() + '')
var daysAgo = subDaysInSchedule('8-5 weekdays', new GlideDateTime() + '', '7');
var date = daysAgo.getDate() + '';
var gr = new GlideRecord('sn_customerservice_case');
gr.addEncodedQuery("auto_close=true^u_account_type=abcd^resolved_at<=javascript:gs.dateGenerate('"+ date +"','23:59:59')^state=6")
gr.query();
gs.info(gr.getEncodedQuery())
while(gr.next()){
gr.state =3;
gr.comments ="This case was auto closed.";
gr.closed_by = 'System Administrator';
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 02:07 AM
Hi @nikhitha24 ,
Please see the OOTB flow in flow designer that just need to be activated: https://docs.servicenow.com/bundle/vancouver-customer-service-management/page/product/customer-servi...
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 03:40 AM
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.👍🇮🇳
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.