Non-Major problem record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 07:58 PM
need to add work notes and close the problem tasks automatically when problem record is moved to closed.
- Labels:
-
Problem Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2025 12:15 AM
below one script is existing one to close the problem record once reached 29 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2025 12:34 AM
Please try the below script in a scheduled job. Please mark my response as helpful or accept as solution, if it helps you.
(function() {
// Set up the 29 day threshold
var days = 29;
var thresholdDate = new GlideDateTime();
thresholdDate.addDaysLocalTime(-days); //get date 29days ago
var probGR = new GlideRecord('problem');
probGR.addQuery('major_problem', false); //non major problem
probGR.addQuery('state', '101'); //state new
probGR.addQuery('sys_created_on', '<=', thresholdDate);
probGR.query();
while (probGR.next()) {
// Close the problem record
probGR.setValue('state', '107');
probGR.update();
//Close problem taks
var taskGR = new GlideRecord('problem_task');
taskGR.addQuery('problem', probGR.getUniqueValue());
taskGR.query();
while (taskGR.next()) {
taskGR.setValue('state', '157'); //set task closed
// Add a work note
var note = "Auto-closed as associated problem record was closed after 29 days.";
taskGR.work_notes.setJournalEntry(note);
taskGR.update();
}
}
})();
Thanks,
Rishi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2025 01:55 AM
Minor correction in my script. There are some Data policies running on problem and problem task table which won't allow us to directly change the state from "new" to "closed". To bypass this we can use gr.setUseEngines(false); Sharing my updated script below.
(function() {
// Set up the 29 day threshold
var days = 29;
var thresholdDate = new GlideDateTime();
thresholdDate.addDaysLocalTime(-days); //get date 29days ago
var probGR = new GlideRecord('problem');
probGR.addQuery('major_problem', false);
probGR.addQuery('state', '101');
probGR.addQuery('sys_created_on', '<=', thresholdDate);
probGR.setUseEngines(false);
probGR.query();
while (probGR.next()) {
// Close the problem record
probGR.setValue('state', '107');
var probUpdated = probGR.update();
//Close problem taks
var taskGR = new GlideRecord('problem_task');
taskGR.addQuery('problem', probGR.getUniqueValue());
taskGR.setUseEngines(false);
taskGR.query();
while (taskGR.next()) {
taskGR.setValue('state', '157'); //set task closed
// Add a work note
var note = "Auto-closed as associated problem record was closed after 29 days.";
taskGR.work_notes.setJournalEntry(note);
taskGR.update();
}
}
})();
If you found my response helpful, please mark it as helpful.
Thanks,
Rishi.