The CreatorCon Call for Content is officially open! Get started here.

Auto close when parent incident is closed automaticcally child incident to be closed and also same

mania
Tera Contributor

Hi,

 

When parent incident is closed then automatically child incident will be closed and When child incident closed then automatically parent incident will be closed (Both sides).

 

How to achieve this and I tried this code but not working for me so can you please give me a code.

 

 

Thanks in Advance!

maniseshua_2-1693313258190.png

 

maniseshua_0-1693313239379.png

 

12 REPLIES 12

Peter Bodelier
Giga Sage

What part of the code is not working for you?

Childs should be closed with this.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

@Peter Bodelier 

 

I need for both of these business rule code When parent incident is closed then automatically child incident will be closed and When child incident closed then automatically parent incident will be closed (Both sides).- both codes are not working can you please provide me working codes.

 

Thanks

Maniseshu

Hi @mania,

 

var parent = new GlideRecord('incident');

if (parent.get(current.parent)){
	if (parent.active){
		parent.state = 7;
		parent.update();
	}
}
else{
	var childs = new GlideRecord('incident');
	childs.addQuery('parent',current.sys_id);
	childs.addQuery('state', '!=', 7);
	childs.query();
	childs.state = 7;
	childs.updateMultiple();
}

 

Try this, and remove the  parent incident is empty from your condition.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

AnveshKumar M
Tera Sage
Tera Sage

Hi @mania 

Try this, I tested this and it is working in my PDI.

 

AnveshKumarM_0-1693315253215.png

 

(function executeRule(current, previous /*null when async*/ ) {
    //Close all childs
    var gr = new GlideRecord("incident");
    gr.addQuery("parent_incident", current.getUniqueValue());
    gr.addQuery("state", "!=", "7");
    gr.query();
    while (gr.next()) {
        gr.setValue("state", "7");
		gr.setValue("close_code", current.getValue("close_code"));
		gr.setValue("close_notes", current.getValue("close_notes"));
        gr.update();
    }

    //Close parent
    var grP = new GlideRecord("incident");
    if (grP.get("sys_id", current.getValue("parent_incident"))) {
        grP.setValue("state", "7");
		grP.setValue("close_code", current.getValue("close_code"));
		grP.setValue("close_notes", current.getValue("close_notes"));
        grP.update();
    }
})(current, previous);

 

 

Thanks,
Anvesh