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

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