Close case when Request closes

steveturley
Tera Guru

I'm trying to find a way to close the case when the associated request closes.

 

As case is the parent of request, I thought I could do this via a business rule without scripting. However I cannot get it to work. I've attached screenshots of my business rule.

 

Any help appreciated - thanks!

 

Case close when Req close rule pic 1.pngCase close when Req close rule pic 2.png

3 REPLIES 3

karimaria
Tera Guru

I don't think you can change values on a parent case like that. You can not change values on a related record using set values.

Can several requests have the same parent?  

Check Advanced and use a script.  When a request is closed, check if all requests with the same parent is closed.  If so get the parent record using GlideRecord and update state on parent to closed.

Choose after in when to run.

OK. The 'use a script' is the tricky bit then!

Try this:

// Query for associated records related to the same parent

var grReq = new GlideRecord('sc_request');
grReq.addQuery('parent', current.parent); // Records related to same parent
grReq.addQuery('sys_id','!=', current.sys_id); // Exclude this record

grReq.addQuery(‘active, true);
grReq.query();
if (!grReq.next()) {
  // If there are no other active records associated to the same parent
  // Close the parent
  var grParent = new GlideRecord('tablename_parent_case');
  grParent.get(current.getValue('parent'));
  grParent.state = 4; // Close the case. Could be another value in your case
  grParent.active = false;
  grParent.update();
}