Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Auto resolve all related incidents when a Change is closed

Tamil5
Tera Expert

Hi All,

I would like to auto resolve all the related incidents when a Change is moved to closed state.

Is it possible ? can anyone share some ideas.

Thanks

1 ACCEPTED SOLUTION

Ian Mildon
Tera Guru

This is a variation on a business rule I had 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();
	    }
	}
}

View solution in original post

3 REPLIES 3

Andrew Barnes -
ServiceNow Employee

Greetings Tamil,

 You can use a flow, a workflow, or a business rule to handle this. You will need to query for the related incidents and close them. If you use a BR you will need to script your query - active=true^rfc=current.getValue('sys_id') 

-Andrew Barnes
Join me at Developer Blog

Ian Mildon
Tera Guru

This is a variation on a business rule I had 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();
	    }
	}
}

Dubeyshubh
Tera Contributor

Hi Tamil5 ,

Try this code in Business Rule and take Change request table and in the condition make sure state would be closed.

 

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

// Add your code here

var gr = new GlideRecord('incident');
gr.addQuery('rfc=',current.sys_id);
gr.query();
while(gr.next()){
if(gr.active == true){
gr.state = '7';
gr.close_notes = "resolved by caller";
gr.close_code = "known error";
gr.update();

}
}


})(current, previous);

 

Dubeyshubh_0-1673805599215.png