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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use after update BR on incident table

Condition: State Changes To Resolved

Query Case table with the current INC and update it

Regards
Ankur

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

Thanks Ankur,

I'm guessing this will be with a script.

Would you be able to guide me with that?

I have something like this, but not sure if it will work.

 

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

var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();

while(caseGr.next()) {

caseGr.resolution_code = 21; // Solved – Related Request is Closed Complete
caseGr.close_notes = 'The related request has been closed';
caseGr.state = 6; //Resolved

caseGr.update();

}

})(current, previous);

OOB case table doesn't have incident field

please use correct field on case table to query; may be you are using parent field

OR

if you are storing case sysId in incident; then query case table with that sysId and update

Regards
Ankur

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