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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 05:40 PM
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.
- Labels:
-
Enterprise Asset Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 06:26 PM
There is OOB BR and scheduled job which does this. "Incident Autoclose". Check that
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 06:51 PM
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:
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 07:06 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 07:18 PM
You may refer the below threads where similar query has been answered:
Business Rule / Scheduled Job - Closure of RITM based on Children
Regards,
Shloke
Regards,
Shloke