I would like to create a scheduled job to close resolved records (incident, u_request & sc_req_item) after 5 business days.

Phil O_shea
Mega Contributor

Hi Gang,

 

I have been trolling through community posts in regards to achieving this.

I found one but it has not quite worked for me as it it is quite specific to the users needs.

I need something a bit more generic to target a wider range of record types.

This is what i have and feel free to tell me how wrong i am ha ha (still learning). 🙂  

 

Run: Periodically

Repeat Interval: 0days,01hours

Conditional: true

--------------------------------------------------------------------

condition:

function notweekend() {

      var now = new Date();

      var day = now.getDay();

      var result = false;

if(day != 6 || day != 7) {

result = true;

}

return result;

}

notweekend();

-----------------------------------------------------------------

Run script:  

 

function autocloserecords() {

var ps = gs.getProperty('glide.ui.autoclose.time');

var pn = parseInt(ps);

var queryTime = new GlideDateTime();

queryTime.addDaysUTC(-pn);

if (pn > 0) {

var gr = new GlideRecord('incident' || 'u_request' || 'sc_req_item');

gr.addQuery('state', State.Resolved);

gr.addQuery('sys_updated_on', '<', queryTime);

gr.query();

while(gr.next()) {

gr.state = State.Closed;

gr.active = false;

gr.closed_by = gr.resolved_by;

gr.update();

 

}

 

}

 

}

----------------------------------------------------------------------------

Regards,

Phil.

10 REPLIES 10

Harish KM
Kilo Patron
Kilo Patron

There is OOB BR and scheduled job which does this. "Incident Autoclose". Check that


Regards
Harish

shloke04
Kilo Patron

Hi,



For Incidents we have a OOB property itself where you can update the Number of Days post which you want to close your Resolved tickets. Navigate to UI properties Module under System properties application menu as shown below and update the property highlighted in below screenshot:



find_real_file.png



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Only issue i have with this is that this doesn't appear to cover requests or requested items.


This is why i wanted to create a scheduled job to cover all of them as we have some of the fore mentioned which are still in a resolved state after the 5 days of resolution.


the back ground of the question is that there are a number of records (including incidents) that are still in a resolved state after the 7 day closure cutoff.


I felt if i could come up with a scheduled job to cover all then i could dispense with all the random business rules and have a singular location for modifying the requirement.


You may refer the below threads where similar query has been answered:



Auto close Requested Items


Business Rule / Scheduled Job - Closure of RITM based on Children



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke