- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:10 AM
Hi,
i want to close PRB when related incidents all closed, if even one incident is in Working Progress then PRB should not closed.should be close all incidents then after only close PRB.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:17 AM
Hi
checkProblem();
function checkProblem()
{
var prbID = current.getValue('problem_id');
//check for any other incidents which are active and are related to the same problem
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('problem_id', prbID);
// inc.addQuery('state', 3); //3 = Pending Problem //Uncomment this line if you want to limit the returned incideent to be in state "Pending Problem"
inc.setLimit(1); //if we find 1 incident no need to search further as we won't close the problem
inc.addQuery('sys_id', '!=', current.getUniqueValue()); //find all incidents but not the current one
inc.query();
//if one record was found => abort
if (inc.next())
return false;
//no record found. Let's close the problem
else {
var prb = new GlideRecord('problem');
if (!prb.get(current.get(prbID))) //just in case we did not find the problem record => abort
return false;
prb.state = 4; //4 = "Closed/Resolved"
prb.work_notes = "Closed problem as all related incidents are closed.";
prb.update();
}
}
Mark correct if it helps.
Warm Regards,
Omkar Mone.
www.dxsherpa.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:45 AM
Hi Omkar,
Script is not working...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:18 AM
A business rule on the 'problem' table with a condition to check when the problem changes to 'Closed' should do the trick. Here is the script for your business rule.
(function executeRule(current, previous /*null when async*/) {
// Query for open incidents and abort if found
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', current.sys_id);
inc.addActiveQuery(); // Only search for active incidents. Replace with query on 'State' if needed
inc.query();
if(inc.hasNext()) {
// If we find even one incident open, abort the update
current.setAbortAction(true);
gs.addErrorMessage('One or more incidents is still open and must be closed before closing this problem record.');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 07:26 AM
it is working for Closed records, can we able to do it for Those incidents are Resolved.