Update related Case when Incident is resolved

Michael Nash
Giga Expert

Good day, how would I fulfil the below requirement.

 

When an incident is set to status 'Resolved' the related case should be populated with:

Resolution Code = Solved

Related Request is Closed Complete

Resolution Notes = The related request has been closed

Set Case to Phase - Propose Solution.

1 ACCEPTED SOLUTION

Michael Nash
Giga Expert

This is the code that worked for me.

 

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

// Add your code here
var gr = new GlideRecord('sn_customerservice_case');
gr.addEncodedQuery('incident='+current.sys_id);
gr.query();
while (gr.next()) {
gr.cause = current.getDisplayValue('close_code');
gr.close_notes = current.close_notes;
gr.resolution_code = 16;
gr.state = 6;
gr.update();
}
})(current, previous);

View solution in original post

7 REPLIES 7

@Michael Nash 

Did you mistakenly marked your own response as correct??

The approach of using after update BR was shared in my response.

Would you mind marking appropriate response as correct?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

shloke04
Kilo Patron

Hi @Michael Nash 

We have this OOB related list available when a Case is linked to an Incident as shown below:

find_real_file.png

Please write a After Update Business Rule on Incident Table as per details below:

BR Details:

Table : Incident

When: After Update

Condition: State Changes to Resolved

Script:

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

	// Add your code here
	var gr = new GlideRecord('sn_customerservice_case');
	gr.addQuery('parent',current.sys_id);
	gr.query();
	while(gr.next()){
		gr.resolution_code = current.getDisplayValue('close_code');
		gr.close_notes = current.getDisplayValue('close_notes');
		gr.Field_OF_CASE = current.getDisplayValue('close_code');
		gr.update();
	}

})(current, previous);

This should work for you.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Michael Nash
Giga Expert

This is the code that worked for me.

 

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

// Add your code here
var gr = new GlideRecord('sn_customerservice_case');
gr.addEncodedQuery('incident='+current.sys_id);
gr.query();
while (gr.next()) {
gr.cause = current.getDisplayValue('close_code');
gr.close_notes = current.close_notes;
gr.resolution_code = 16;
gr.state = 6;
gr.update();
}
})(current, previous);