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

palanikumar
Giga Sage

You can create a Business rule for this. Create a BR in Change Request table with condition state changes to closed. In the script you can get the incident and set state to resolved.

Thank you,

Palani

Thank you,
Palani

Voona Rohila
Kilo Patron
Kilo Patron

Hi RAM

Refer below links for approach

https://community.servicenow.com/community?id=community_question&sys_id=0870da37dbfaab00656a5583ca96...

https://community.servicenow.com/community?id=community_question&sys_id=866c07a5db9cdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=68758faddbd8dbc01dcaf3231f96...


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

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

Community Alums
Not applicable

Hi RAM,

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep