Close case when Request closes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 04:06 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 02:00 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 04:31 AM
OK. The 'use a script' is the tricky bit then!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 03:11 PM
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();
}