When the Child incident are closed automatically parent incident should be closed?

arey yaar
Giga Guru

I created a table(Razor) which acts as child to the incident table. When the State in every child record is changed to Closed State,then the parent Incident Table should automatically..close the Incident Ticket..

Note:"i doesn't want to populate the result to the incident,it should automatically close when the child incidents are closed" 

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

You'll want to run an 'After Update' business rule on the 'u_razor' table that looks like this...

Condition: current.active.changesTo(false) && current.parent.sys_class_name == 'incident'

Script:

// Query for associated records related to the same parent
var inc = new GlideRecord('u_razor');
inc.addQuery('parent', current.parent); // Records related to same parent
inc.addQuery('sys_id' '!=', current.sys_id); // Exclude this record
inc.addActiveQuery();
inc.query();
if (!inc.next()) {
    // If there are no other active records associated to the same parent
    // Close the parent
    var parInc = new GlideRecord('incident');
    parInc.get(current.getValue('parent'));
    parInc.state = 7; // Close the incident
    parInc.active = false;
    parInc.update();
}

View solution in original post

6 REPLIES 6

Mark Stanger
Giga Sage

You'll want to run an 'After Update' business rule on the 'u_razor' table that looks like this...

Condition: current.active.changesTo(false) && current.parent.sys_class_name == 'incident'

Script:

// Query for associated records related to the same parent
var inc = new GlideRecord('u_razor');
inc.addQuery('parent', current.parent); // Records related to same parent
inc.addQuery('sys_id' '!=', current.sys_id); // Exclude this record
inc.addActiveQuery();
inc.query();
if (!inc.next()) {
    // If there are no other active records associated to the same parent
    // Close the parent
    var parInc = new GlideRecord('incident');
    parInc.get(current.getValue('parent'));
    parInc.state = 7; // Close the incident
    parInc.active = false;
    parInc.update();
}

Thank you mark for your reply...

u haven't mentioned about the child table's State..how come incident know the State of the child table..to close the incident

We know about the child table state because that is where the business rule is triggered from.

I tried to count the child records (i.e) present in child (blade) it closes the incident when one child record is closed..it need to check for every child record whether it is  closed or not and then close the incident ticket 

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

var gr = new GlideRecord('incident');

	if (gr.get(current.u_business_service)) {

		if (checkchild(current.sys_id)) {
			gs.addInfoMessage('All child incidents are now resolved');
			gr.state=7;
			gr.close_code = 'Solved (Work Around)';
			gr.close_notes = 'The incident is Resolved as the Related Problem is Closed/Resolved';
			gr.update();
		}

		else {
			gs.addInfoMessage('Not all child incidents are resolved');
		}
	}
	else {
		gs.addInfoMessage('Current incident does not have a parent incident');
	}

	function checkchild(parentID) {
	
		var rec = new GlideRecord("u_blade");
		rec.addQuery("parent_incident", parentID);
		rec.addActiveQuery();
		rec.query();
		var c=rec.getRowCount();
		if (c.hasNext()) {
			gs.addInfoMessage('child incident are closed');
			return true;
		}
		else {
			gs.addInfoMessage('child incidents  not closed');
			return false;
		}
	}
})(current, previous);