When Change request was closed , automatically associated incidents also closed?

RAM75
Tera Contributor

When Change request was closed ,automatically associated incidents also closed?

Scenario: We want closed incidents automatically, associated with Change request. When change request closed.

Thanks

1 ACCEPTED SOLUTION

Community Alums
Not applicable

HI RAM,

This is a variation on a business rule used for Problem to resolve related incidents, it should do the trick for you; or at least point you in the direction.

if (current.state.changesTo(3)) {
	notifyRelatedIncidents(current);
}

// 
// Notify any incidents that are related to the current change
//
function notifyRelatedIncidents(me) {
var incident = new GlideRecord("incident");
incident.addQuery("rfc", "=", me.sys_id);
incident.query();
while (incident.next()) {
	if (incident.active == true){
	var msg = "Associated change request " + me.number + ' closed with the following close notes.\n' + 'Close Notes:\n' + me.close_notes;
	if(incident.state != 6,7){
	    incident.state.setValue(6);
	    }
	        incident.work_notes = msg;
	        incident.update();
	    }
	}
}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

View solution in original post

5 REPLIES 5

Richard P
Mega Guru

assuming you have made a relationship to the incident table, with a field in the incident identifying the change

 

var gr = new GlideRecord("incident");
gr.addQuery("change", current.sys_id);
gr.query();
while (gr.next()) {
gr.state= 'x' ;  //where x is the value of the state you want the incident in as you may want resolved or closed.

gr.update();
}