when related incident are closed the problem should close automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â04-03-2023 02:03 AM - edited â04-03-2023 02:05 AM
->when related incidents are closed the problem should close automatically. Even one incident is open the problem should not close it should show a pop-up message like please close the incident.
->This is the code I'm using but it's not working I think we have to glide the problem table and fetch how many incident records are there
->How to Glide the problem table and fetch how many incidents records are there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â04-03-2023 03:39 AM
So you just want to close the problem when the last incident is closed?
Yes, you need to do a GlideRecord query on the problem table as you can't dot walk to update it.
Here's an example script for closing the problem:
var problemID = current.getValue('problem_id');
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', problemID);
inc.addQuery("stateNOT IN6,7,8");
inc.query();
if(!inc.hasNext()){
var problem = new GlideRecord('problem');
problem.get(problemID);
problem.state = '107';
problem.update();
}
You don't need to do any extra tricks. Simply make sure this script is on a AFTER update BR, so that the current incident is also properly closed. Then, when this BR runs, it checks whether any are active and closes the problem if none are. You could include an alert to notify that problem was also closed.
The condition checks that there are no incidents with state Resolved, Closed or Cancelled. Resolved is an active state, so it would show up with addActiveQuery, so you need to separately check the states instead.
After query you can check inc.hasNext() which will be true if the query returns any records. By adding a "!" before it we are reversing the result. Basically true becomes false and vise versa. In this case if no records are found we'll get true in the if condition and the script will then update the problem state.