Auto close Requested Items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2013 03:34 AM
I am trying to create a Business Rule that auto closes Requested Items (we ignore Requests) if they have not been updated whilst in a Resolved state for 5 days. There is a BR for Incidents which works fine, using the System Property 'glide.ui.autoclose.time'. I tried to recreate this script for ReqItems but it just doesn't work. Here is the code:
// This script automatically closes request items that are resolved
// and haven't been updated in the specified number of days.
autoCloseReqItems();
function autoCloseReqItems() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if (pn > 0) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', '4');
gr.addQuery('u_review_required', 'false');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
gr.query();
while(gr.next()) {
gr.state = '3';
gr.comments = 'Request automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}
Any ideas why this doesn't work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2013 05:51 AM
autoCloseReqItems();
function autoCloseReqItems() {
var pn = 5;
if (pn > 0) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', '4');
gr.addQuery('u_review_required', 'false');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
gr.query();
while(gr.next()) {
gr.state = '3';
gr.comments = 'Request automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2013 09:55 AM
Thanks. I've changed it. I'll see if it works tomorrow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2014 01:56 PM
Hello Neetu
I tried implementing the code you suggested (for Service Catalog Item) - except that I'm trying to do this for Defects. Wherein if a defect has been in a 'Fixed' state for 5 days it should automatically close out.
Here is the code I'm trying to implement.
I implemented this as a Scheduled Job. However, when i click 'Execute Now', the defects that are in a 'Fixed' state don't close out). Can you please suggest a workaround.
Thanks!
Nomaan
// This script automatically closes defects that are in a Fixed state for a specified number of days.
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line.
// Fixed state (value = 15), closed state (value = 😎
autoCloseDefects();
function autoCloseDefects() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = 5;
if (pn > 0) {
var gr = new GlideRecord('rm_defect');
gr.addQuery('state', '8');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
gr.query();
while(gr.next()) {
gr.state = '15';
// gr.comments = 'Defect automatically closed after ' + pn + ' days in the Fixed state.';
gr.active = false;
gr.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2013 01:54 PM
You called this a business rule. I think you need this to be a scheduled job. Otherwise, what makes it fire?
And you shouldn't have to wait until tomorrow to test your job. Just Click on "Execute Now".