Close parent task if all child tasks are closed

Rishabh Mehta
Giga Contributor

Hi All,

I have a requirement to close the parent if all child tasks are closed / put parent on hold if all children are on hold / withdraw parent if all children are withdrawn. It is basically to be done for a scoped application CONTINUAL SERVICE IMPROVEMENT. 

Here the parent is CSI Plan and child is CSI task. There is a field called csi plan (reference field) present on the CSI task form to show that the task is related to that specific CSI plan. 

 

Regards,

Rishabh

6 REPLIES 6

Deepak Ingale1
Mega Sage

Hello, 

Below logic must work for your, I have assumed for 1 case when child tasks are close, likewise you can modify the code for other scenarios as well.

 

Note: Please mark reply as correct / helpful if it answers your original question.

 

// write a Business rule on child table whenever state of the child record is changed

var otherTasksHasSameState = true;

var gr = new GlideRecord("childTable");
gr.addQuery("parentTableReferenceField", current.parentTableReferenceField);
gr.addQuery("sys_id", "!=", current.getValue("sys_id"));
gr.query();

while (gr.next()) {
	if (gr.getValue("state") != current.getValue("state")) {
		otherTasksHasSameState = false;
		break;
	}
}


if (otherTasksHasSameState && current.state == "3") { // I assume 3 means closed
	var pGr = new GlideRecord("parentTable");
	pGr.addQuery("sys_id", current.parentTableReferenceField);
	pGr.query();

	if (pGr.next()) {
		pGr.state = 3;
		pGr.update();
	}
}

Hi Deepak,

Thank you so much for your reply. Since i am new to this, can you please explain this code a little bit please.

Regards,

Rishabh

Hello,

 

This business rule should run on child task whenever child task state is getting changed.

It checks if other child tasks for same parent record are having the same STATE value.

 

If state of other child tasks are not same as current task getting modified, it sets the flag "otherTasksHasSameState" to false.

If STATE of other child tasks are same as current task, "otherTasksHasSameState" remains true.

 

Then we update the parent record if "otherTasksHasSameState" is true

 

 

what to add in ?

current.parentTableReferenceField