- 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-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-28-2020 04:24 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
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
ā11-22-2021 04:34 AM
I need same logic, for resolved.
That is when an incident goes to resolved after 5 week days it has to close automatically. please suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-30-2022 04:45 AM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
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
ā03-09-2022 01:46 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader