- 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!