- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 01:03 PM
Is there a way to setup parent/child relationships for HR Case. I know for Incidents you can click Configure > Related Lists and then add then select Incident > Parent Incident. I am not seeing an option like this for Hr Case (HR Case > Parent HR Case).
Is this the preferred method for creating Parent and child cases. I haven't found any clear directions on how to set this up properly so users will have the ability to open a new case, designate it as a master (parent) and link other similar cases to it. Any comments/state changes made on master cases would flow to child case.
If anyone has any ideas let me know.
Thank you,
Lorenzo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2017 02:11 PM
Cool glad you got the right related list going. The functionality you describe of updating the children is out of the box and part of Incident Management. There is a specific Parent Incident field and this is managed in a business rule called "Update Child Incidents". This functionality doesn't exist on Task because there are field differences but you can definitely clone the Update Child Incidents business rule and set it against the HR Case table and modify it to your needs.
Please mark any of these posts helpful and/or the answer to your question so others can benefit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 10:29 AM
I didn't realize how messy that out of the box script was! Few questions so I can help you:
- What is your HR case table name? It used to be "hr_case" but recent releases made HR a scoped application and the new table name is "sn_hr_core_case" so just want to make sure what version you are using.
- What is the actual numeric value of a resolved case? I don't see a Resolved state out of the box and need to confirm the actual database value, not the label. You can view this by right clicking on a resolved case and choose Show XML and then scroll down to State and let me know the numeric value. If resolved is not what you use, then tell me that numeric value instead, such as closed.
- Please confirm you have a field named "parent_hr_case". I figured you were using the out of the box "parent" field instead.
- Please confirm you have a field named "hr_case_state". I figured you were using the out of the box "state" field instead.
- Please confirm you have a field named "close_code" as that doesn't exist on the out of the box hr table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 12:56 PM
Thanks,
1. What is your HR case table name? It used to be "hr_case" but recent releases made HR a scoped application and the new table name is "sn_hr_core_case" so just want to make sure what version you are using. hr_case
2. What is the actual numeric value of a resolved case? I don't see a Resolved state out of the box and need to confirm the actual database value, not the label. You can view this by right clicking on a resolved case and choose Show XML and then scroll down to State and let me know the numeric value. If resolved is not what you use, then tell me that numeric value instead, such as closed. We actually use Closed and the numeric value is 3. We sometimes use resolved (-1) which auto closes in three days.
3. Please confirm you have a field named "parent_hr_case". I figured you were using the out of the box "parent" field instead. I do not have a field "parent_hr_case", is this something I need to create? We did however add a field called Master case which is a checkbox field that we can use to designate a case as a master for reporting purposes.
4. Please confirm you have a field named "hr_case_state". I figured you were using the out of the box "state" field instead. No field hr_case_state, we are using "state"
5. Please confirm you have a field named "close_code" as that doesn't exist on the out of the box hr table. There is no field called "closed code"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 02:35 PM
OK thanks for the answers. Delete the business rule you created from the "Update Child Incidents" business rule. It was created so long ago, the scripting requirement have changed a little, plus we can now use the condition builder to set the conditions to run. And the code in that business rule is very hard to follow and I made this much more efficient.
Create a new business rule for your hr_case table. Since you want this to run on both Resolved and Closed, I modified the condition to look for state changes and the script will take care of the specific values. Set the following Filter conditions:
Then click the Advanced tab and set your script to the following:
(function executeRule(current, previous /*null when async*/) {
//Setup an array to push changes to.
var fieldMap = [];
if (current.state.changesTo(-1) || current.state.changesTo(3)) {
fieldMap.state = current.state;
}
if (current.comments.changes()) {
fieldMap.comments = "Comment copied from Parent Case: \n" + current.comments;
}
if (current.work_notes.changes()) {
fieldMap.work_notes = "Work notes copied from Parent Case: \n" + current.work_notes;
}
if (current.close_notes.changes()) {
fieldMap.close_notes = "Close notes copied from Parent Case: \n" + current.close_notes;
}
updateChildren(fieldMap);
function updateChildren(fieldMap) {
var keys = Object.keys(fieldMap).toString();
var keysList = keys.split(",");
if (keysList.length > 0) {
var childRec = new GlideRecord("hr_case");
childRec.addQuery("parent", current.sys_id);
childRec.addQuery("state", "!=", -1);
childRec.addActiveQuery();
childRec.query();
while (childRec.next()) {
for (var i = 0; i < keysList.length; i++) {
var fieldName = keysList[i];
var fieldValue = fieldMap[fieldName];
if (!gs.nil(fieldValue))
childRec[fieldName] = fieldValue;
}
childRec.update();
}
}
}
})(current, previous);
As you will see above I use an array to set the values that should be updated on the child cases. I then call a generic function to loop through those updates to update the case. Feel free to change any of the verbiage or add additional fields at the top that you want to edit on the child case. The format for other fields is fieldMap.COLUMN-NAME
Please mark this post helpful if it solves your issue. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 05:15 PM
Hey Michael,
Thanks for your assistance, the new business rule works and child cases are updating as desired. Yes this is much more efficient and easier to understand and adding additional fields are pretty straightforward.
I can't thank you enough for taking the time to assist with this.
Lorenzo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2017 10:34 AM
Hey Michael,
Didn't know if you would see this but I few other questions arose concerning the parent and child hr cases. I think using hr task would be better but other have decided that's not the path they'd like to take.
When creating the child hr case is there a way to pull current field values from the parent case into the child. I have tried adding the below code to the beginning of the script you provided (see screenshot below). Question is should/could this be added to the current business rule or should be accomplished with an UI Action or some script. Also, is it possible to copy any attachments on the parent case to the child case? and how to access those, I'm not seeing them on the task table. Finally, is there a way to identify what cases are parent or child cases?
Thanks in advance for any insight you could provide on this.
Lorenzo