How to Close Problem Record when only all related incidents closed

chanikya
Kilo Sage

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.

 

find_real_file.png

1 ACCEPTED SOLUTION

Sure. Just add this line below the addActiveQuery line. inc.addQuery('state', '!=', 6);

View solution in original post

12 REPLIES 12

Omkar Mone
Mega Sage

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

 

Hi Omkar,

 

Script is not working...

Mark Stanger
Giga Sage

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);

it is working for Closed records, can we able to do it for Those incidents are Resolved.