Closed child incident when the parent incident close

Payal Tripathy
Tera Contributor

When the incident moved to closed all the child incidents also moved to close.

4 REPLIES 4

Namrata Ghorpad
Mega Sage
Mega Sage

Hello @Payal Tripathy ,

 

Create after update Business rule on incident table and select condition like state is closed and write below code in script section.

var grInc= new GlideRecord('incident');
grInc.addQuery('parent',current.sys_id);
grInc.query();
while(grInc.next())
{
grInc.state=7;
grInc.update()
}

Please refer the below link.

https://www.servicenow.com/community/developer-forum/close-child-incident-state-after-parent/m-p/163... 

 

Please mark my answer as helpful and correct if it resolves your issue.

Regards,

Namrata

Community Alums
Not applicable

Hi @Payal Tripathy .

Please create a Before Business Rule on incident table and add Below script 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (current.state == 7) {
		gs.log("Inside Close inc = " + current.state, 'closeINc');
        current.close_code = 'User Error';
        current.close_notes = 'TESTETST';
        var gr = new GlideRecord('incident');
        gr.addQuery('parent_incident', current.sys_id);
        gr.query();
        while (gr.next()) {
			gs.log("Child Parent = " + gr.parent_incident + " CUrrent = " + current.sys_id, 'closeINc');
			gs.log("Inside while = " + gr.number, 'closeINc');
            gr.setValue('state', 7);
			gr.setValue('close_code', 'User Error');
			gr.setValue('close_notes', "TESTETETS");
			gr.update();
        }
    }

})(current, previous);

 

SarthakKashyap_0-1715536625612.png

 

SarthakKashyap_1-1715536676615.png

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Krushna R Birla
Kilo Sage

Hi @Payal Tripathy 

 

You can create after update business rule and add condition as when state changes to closed on incident table.

Add below script:

 

(function executeRule(current, previous /*null when async*/ ) {

var grInc = new GlideRecord('incident');
grInc.addQuery('parent_incident', current.sys_id);
grInc.query();
while (grInc.next()) {
grInc.state = 7;
grInc.update();
}

})(current, previous);
 
KrushnaRBirla_1-1715539874161.png

 

KrushnaRBirla_0-1715539850009.png

 

 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

swathisarang98
Giga Sage
Giga Sage

Hi @Payal Tripathy ,

 

You can do it through script or achieve it through OOTB solution,

 

OOTB solution,

when Parent incident is resolved, it resolves the child incident aswell and it will be closed based on the days set in the incident property.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0994346 

 

Through script:

Write after update business rule on Incident table,

Condition: State is closed

swathisarang98_0-1715542677706.png

swathisarang98_1-1715542691121.png

 

 

 

(function executeRule(current, previous /*null when async*/) {

	var childInc = new GlideRecord('incident');
	childInc.addQuery('parent_incident',current.sys_id);
	childInc.query();
	while(childInc.next()){
		//gs.info('inside while');
		childInc.state = "7" ;
		childInc.incident_state = "7" ;
		childInc.close_code = current.close_code;
		childInc.close_notes =current.close_notes;

		childInc.update();
	}

})(current, previous);

 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang