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

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep

Community Alums
Not applicable

Hi 

Hritik

can you help me can i get full code for this requirement how you have achieved for problem.

 

Regards

Jyothinath

Hello Hritik

Could you please me to get the complete code in order to fulfill the requirement ?

 

Thanks in advance

Nagurbee

Evan McElfresh
Giga Guru

@Community Alums @Nagurbee1  and anyone else looking for a clean answer to this:

 

Use Flow Designer!

 

  • Trigger: Scheduled Daily
  • Action 1: Look up records with the following conditions:
    • State is Resolved, and
    • Updated | Relative | Before | 7 Days ago, and
    • Resolved | Relative | Before | 7 Days ago
  • Action 2: For each item in Action 1
  • Action 3 in the 'For each loop' from Action 2: Update Record with the following fields:
    • Problem state | Closed
    • State | Closed
    • Work Notes | "System auto-closed Problem after being in Resolved state for 7 days"
    • Closed by | Action 2 > Problem Record > Resolved by
Please mark this response as correct and/or helpful if it assisted you with your question.