- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 11:21 PM
Hi all,
Please help me with this below requirement.
We are using incidents properties OOB to move incidents to closed state after 5 days once the incident state is set to resolved. This will run in weekends as well. can we restrict this to run only for 5 working days in a week.
If yes please help me with the right way to achieve this.
Thank you,
Balaram.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 04:50 AM
Create schedule job which runs daily and use below script
It would check if the days between created and now time is more than 5 working days i.e. the difference is excluding weekends
updateRecords();
function updateRecords(){
try{
var inc = new GlideRecord('incident');
inc.addQuery('state', 6);
inc.query();
while(inc.next()){
var start = new GlideDateTime(inc.sys_created_on);
var nowTime = new GlideDateTime();
var days = getDateDiffExcWeekends(start,nowTime);
// if days more than 5
if(days >=5){
inc.state = 7;
inc.incident_state = 7;
inc.active = false;
inc.update();
}
}
}
catch(ex){
gs.info(ex);
}
}
function getDateDiffExcWeekends(start , end){
var days = 0;
while (start < end) {
start.addDaysUTC(1);
if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7){
days++ ;
}
}
return days;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 11:24 PM
Hi Balaram,
navigate to Incident > Administration > Incident Properties and change the value in the field "Number of days" (first field, OOB populated with 7), change it to 5.
cheers, hope that helps /Tommy
*** Please mark as "Correct" or "Helpful" as appropriate ***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 11:34 PM
Ah, I didn't read properly. To do this for business days you will need a scheduled job. This has been discussed here: https://community.servicenow.com/community?id=community_question&sys_id=fea443e9dbd8dbc01dcaf3231f96...
cheers, hope that helps /Tommy
*** Please mark as "Correct" or "Helpful" as appropriate ***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 11:46 PM
Hi,
You would require daily schedule job
refer below links for help
Auto close resolved incidents after 7 business days
Customize the automatic closure of incidents
Auto close resolved incidents after 3 business days
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 04:28 AM
Hi Ankur,
Could you please help me with the business rule and the scheduled job need to be updated.
to resolve this issue.
Thank you,
Balaram.