Once Parent Incident Status Changes, Child Ticket Status Should Change automatically for all the states

SNOW46
Tera Contributor

Hello All,

We are getting a conflict in our current scenario as whenever the Parent Incident Status changes to OnHold and On-hold reason is any one of the reasons from the drop-down, the corresponding Child Incident Status is not getting automatically changed to OnHold. Because of this, the SLA is getting breached in our Child Incidents which is very critical.

 

Can anyone let me know how to fix this asap?

Thanks

15 REPLIES 15

Hi Musab,

I didn't find any such Business Rule OOB for the link which you have provided.

I replaced my Instance Name but I can't find any.Can you please help me with the BR Name or it will be great if you can share with me the detailed script?

 

Thanks

Please take this. Mark my answer as correct and close the thread. create the Same BR with same name and same order.

Name , when to run.

find_real_file.png

 

Conditions :

current.isValidRecord() && (current.incident_state.changes() || (current.incident_state == IncidentState.ON_HOLD && current.hold_reason.changes())) && (current.child_incidents > 0)

 

Script:

 

synchChildIncidents();

function synchChildIncidents() {
	var updateChildState = false;
	var updateOnHoldReason = false;
	var ON_HOLD_REASON_AWAITING_CALLER = 1;
	if ((current.incident_state.changes() && current.incident_state != IncidentState.RESOLVED && current.incident_state !=
			IncidentState.CLOSED && current.incident_state != IncidentState.CANCELED &&
			!(current.incident_state == IncidentState.ON_HOLD && current.hold_reason == ON_HOLD_REASON_AWAITING_CALLER)
		) ||
		(current.incident_state == IncidentState.ON_HOLD && current.hold_reason != ON_HOLD_REASON_AWAITING_CALLER)) {
		updateChildState = true;
	}
	if (current.incident_state == IncidentState.ON_HOLD && current.hold_reason && current.hold_reason.changes() &&
		current.hold_reason != ON_HOLD_REASON_AWAITING_CALLER) {
		updateOnHoldReason = true;
	}
	if (updateChildState || updateOnHoldReason)
		updateChildIncidents(updateChildState, updateOnHoldReason);
}

function updateChildIncidents(updateChildState, updateOnHoldReason) {
	var gr = new GlideRecord("incident");
	gr.addQuery("parent_incident", current.sys_id);
	var lastReopenedBy = gs.getUser().getUserByID(current.reopened_by);
	if (!lastReopenedBy.hasRole("itil,sn_incident_write"))
		gr.addQuery("incident_state", "!=", IncidentState.RESOLVED);
	gr.addQuery("incident_state", "!=", IncidentState.CLOSED);
	gr.addQuery("incident_state", "!=", IncidentState.CANCELED);
	var qc = gr.addQuery("incident_state", "!=", current.incident_state);
	if(updateOnHoldReason)
		qc.addOrCondition('hold_reason', "!=", current.hold_reason);

	gr.addActiveQuery();
	gr.query();
	if (updateChildState) {
		gr.setValue("incident_state", current.incident_state);
		gr.setValue("state", current.state);
	}
	if (updateOnHoldReason)
		gr.setValue("hold_reason", current.hold_reason);
	gr.updateMultiple();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab,

Shall I inactive the existing BR which I created earlier?

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

	// Add your code here
	gs.addInfoMessage("Working fine");
	var incident = new GlideRecord('incident');
incident.addQuery('parent_incident', current.sys_id);
// incident.addQuery('state', '3');
// 	incident.addQuery('hold_reason', '1');
incident.query();
while(incident.next()){
gs.addInfoMessage("Working fine fine");
incident.state = current.state;
incident.hold_reason = current.hold_reason;
incident.update();

}

})(current, previous);

And create a New BR with the new script which you have provided yesterday?

 

Thanks

Hi Musab,

I have also one more last query that is this new script should work for all the OnHold Reasons as below.

find_real_file.png

Or it shall work only for Awaiting Caller? Can you please confirm this and let me know so that I can work on configuring the new script and mark your answer as Helpful for others.

 

Thanks

Hi,

If your query is resolved please mark my answer as correct and close the thread.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab