How to Close Problem Records automatically after 5 days ???

Hritik1
Tera Contributor

Hey Community,

I want to auto-close the problem records that are resolved after 5 days. I have so far followed below steps :

1. Created a Business Rule with below script : 

// This script automatically closes problems that are resolved
// and haven't been updated in the specified number of days.
// This number is a property in System Properties.
// To place a comment in the incident, uncomment the "gr.comments" line..

autoCloseProblems();

function autoCloseProblems() {
var ps = gs.getProperty('glide.ui.autocloseproblem.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);

if (pn > 0) {
var gr = new GlideRecord('problem');
gr.addQuery('state', 6);
// gr.addQuery('sys_updated_on', '<', queryTime);
gr.addQuery('sys_updated_on', ''<'', gs.daysAgo(pn));
gr.query();
while(gr.next()) {
gr.state = 7;
// gr.comments = 'Problem automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.closed_by = gr.resolved_by;
gr.update();
}
}
}

2. Created a Schedule Item

3. Created a system property : glide.ui.autocloseproblem.time 

I tried adding 1 min as trigger as well as 1 hour trigger in schedule item. But still above configuration is not working. Kindly let me know what am I doing wrong ??

As I see we do have OOTB for Incidents autoclosure but not for problems. Please help me with the requirement. 

 

Thanks,

Hritik

8 REPLIES 8

Community Alums
Not applicable

Hi,

Use this thread for your help :

https://community.servicenow.com/community?id=community_question&sys_id=d50c32c2dbc027042be0a851ca96...

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Hi Sandeep,

I used the same thread for creating above configurations. But no luck ! 😞

 

Thanks,

Hritik

Hi I did the same thing to close Inc for 10 days. You can modify the script Write a schedule job which will run daily
Regards
Harish

Hritik1
Tera Contributor

Requirement achieved. thanks community