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

Abhinay Erra
Giga Sage

Create an after business rule on incident table

 

when: After insert and update

Conditions: state changes to Closed AND Problem is not empty AND Problem.state is not closed

Script:

var gr= new GlideRecord("incident");

gr.addQuery("problem_id",current.getValue("problem_id"));

gr.addQuery("sys_id",'!=',current.getValue("sys_id"));

gr.addQuery('state','!=','7');

gr.query();

if(!gr.hasNext()){

var prb= new GlidRecord("problem");

prb.get(current.getValue("problem_id"));

prb.state='7';

prb.update();

}

you script is working in redirectional way..

when PRB closed then INC's resolved ......but my Request is when you try to Close PRB then it ishould check all INC 's are closed or Not, even one INC in active then should not allow to PRB close.

Abhinay Erra
Giga Sage

Here you go. Before business rule on problem table

 

When: before insert and update

Conditions: State changes to closed

script:

var gr= new GlideRecord("incident");
gr.addQuery("problem_id",current.getValue("sys_id"));
gr.addQuery('state','NOT IN','6,7');
gr.query();
if(!gr.hasNext()){
gs.addErrorMessage("Problem cannot be closed becuas ethe associated incident are not resolved/closed");
current.setAbortAction(true);

}