When all the child records are closed, auto close the parent record if the parent record is in state

purnendutiw
Tera Contributor

HI,

 

I have one question..

 

When all the child records are closed, auto close the parent record if the parent record is in state “On Hold”.

Any help will be thankfull.

Thanks in advance.

1 ACCEPTED SOLUTION

sarthakkash
Kilo Guru

Hi @purnendutiw ,

I tried your problem in my PDI and it worked for me please check solution below 

Create after business rule on particular table(I take incident table) and add below code 

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

	// Add your code here
	gs.log("Current State = " + current.state);
	if(current.state = 3){ // On Hold state
		gs.log("Inside if  = " + current.state);
		var parentInc = new GlideRecord('incident');
		parentInc.addQuery('state', 3);
		parentInc.query();
		if(parentInc.next()){
			gs.log("Inside Parent inc");
			var childInc = new GlideRecord('incident');
			childInc.addQuery('parent_incident', current.sys_id);
			childInc.addQuery('state', 7);//close
			childInc.query();
			if(childInc.next()){
				gs.log("Inside Child Inc While");
				parentInc.state = 7;
				parentInc.close_code = "Duplicate";
				parentInc.close_notes = "test";
				parentInc.update();
				gs.log("After update");
			}
		}
	}

})(current, previous);

 

sarthakkash_0-1735412258553.png

 

 

 

sarthakkash_1-1735412258607.png

 

 

 

Result 

sarthakkash_2-1735412258564.png

 

 

sarthakkash_3-1735412258611.png

 

 

 

 

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

Thanks and Regards 

Sarthak

View solution in original post

6 REPLIES 6

sarthakkash
Kilo Guru

Hi @purnendutiw ,

I tried your problem in my PDI and it worked for me please check solution below 

Create after business rule on particular table(I take incident table) and add below code 

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

	// Add your code here
	gs.log("Current State = " + current.state);
	if(current.state = 3){ // On Hold state
		gs.log("Inside if  = " + current.state);
		var parentInc = new GlideRecord('incident');
		parentInc.addQuery('state', 3);
		parentInc.query();
		if(parentInc.next()){
			gs.log("Inside Parent inc");
			var childInc = new GlideRecord('incident');
			childInc.addQuery('parent_incident', current.sys_id);
			childInc.addQuery('state', 7);//close
			childInc.query();
			if(childInc.next()){
				gs.log("Inside Child Inc While");
				parentInc.state = 7;
				parentInc.close_code = "Duplicate";
				parentInc.close_notes = "test";
				parentInc.update();
				gs.log("After update");
			}
		}
	}

})(current, previous);

 

sarthakkash_0-1735412258553.png

 

 

 

sarthakkash_1-1735412258607.png

 

 

 

Result 

sarthakkash_2-1735412258564.png

 

 

sarthakkash_3-1735412258611.png

 

 

 

 

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

Thanks and Regards 

Sarthak

Uncle Rob
Kilo Patron

This video teaches you how to do what you're asking for in Flow Designer (more or less).
You just need to add a condition somewhere that factors for the parent on hold condition.