Auto close resolved incidents after 3 business days

nikhitha24
Tera Guru

Hi all,

 

Please help me with this below requirement.

After resolving of my incident it need to be closed 3 business day.

I have written a scheduled job for this, but it is not working.

please help me with the right way to achieve this.

 

updateRecords();
function updateRecords(){

try{
var inc = new GlideRecord('incident');
inc.addQuery('state', 6);
inc.query();
while(inc.next()){

var start = new GlideDateTime(inc.sys_resolved_at);
var nowTime = new GlideDateTime();

var days = getDateDiffExcWeekends(start,nowTime);
// if days more than 3
if(days >=3){
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;
    }

 

 

Thank you,

Nikhitha

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@nikhitha24 

solution is present in this link. check that and enhance

Auto closure of Task after 3 business days 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

AndersBGS
Tera Patron
Tera Patron

Hi @nikhitha24 ,

 

Why don't you use the OOTB incident properties list instead of a script:

 

AndersBGS_0-1691664666992.png

 

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/

@AndersBGS 

The OOTB properties will work on all the days. in my requirement i want to be check for the business days only.

Utpal Dutta
Tera Guru

Hi Nikhitha,

You don't need to write a scheduled job. There is (Autoclose Incidents) scheduled job available out of the box. You can modify this Scheduled job if you want to. 

For more info please follow this link it has everything described.

 

If my answer helps then please mark it Helpful or Correct!

 

Thanks,

Utpal

@Utpal Dutta1 

I have changed it 3 business days, still it is not working.

Please help on this