- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-22-2022 02:22 PM
Hi All,
I hope you all are doing fine.
recently I received a private message from one of my friends on the NOW community where she was looking for the use case which is as described below :
Symptoms
How to update child incident when parent incident is updated.
This is a general use case, in which we have to update the child record based on the parent record and vice-versa.
Diagnosis
To solve this we have to first understand the use case carefully and as always I use to do let's have some QandA on the same.
- What do we want to achieve ? --> Real-time update of child incident based on parent incident update
- What fields do we want to update? --> We can dynamically configure it out in my script I have created an array called 'monitorFields' which will hold all the fields which should get updated when it gets updated on the parent record (Inn the ideal case you can put these values on the system property)
- How we will get all the changed values on the record? --> These values will be extracted as a part of the array 'changedFields' which will be derived by comparing the current and previous values for that field
Solution
- Create an On After Business rule on the incident table
- Define the trigger condition based on the fields you wanna monitor. In our case monitored fields are as given: 'caller_id','state','impact','description' (You can add or remove as per your use case)
- Write Script as given below:
/**
* @Description : Update Child incident based on parent incident
* @monitorFields : Fields to be moniter to be updated on the child record
* @changedFields : Fields which are getting updated
* @changedMnitorFields : Array of monitor fields which got changed
**/
(function executeRule(current, previous /*null when async*/) {
var monitorFields = ['caller_id','state','impact','description']; // Fields to be moniter to be updated on the child record
var changedFields = []; // Fields which are getting updated
for (var x in current){
if (current[x] != previous[x]) {
changedFields.push(x);
}
}
var changedMnitorFields = changedFields.filter(function (ele) { // Get the array of monitor fields which got changed
return monitorFields.indexOf(ele) != -1;
});
var grIncident = new GlideRecord('incident');
var query = gs.getMessage('parent_incident={0}^active=true',[current.getUniqueValue()]); // Get all the Active child incident
grIncident.addEncodedQuery(query);
grIncident.query();
while (grIncident.next()) {
changedFields.forEach (function (ele) {
grIncident[ele] = current[ele];
});
grIncident.update();
}
})(current, previous);
Please be sure to bookmark this article as well as mark it as Helpful if you thought it was helpful.
Regards,
Amit Gujarathi
- 4,830 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks a lot Amit for your response. It helped a lot.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If all the child incidents are "resolved" that are related to a parent incident, then
Parent incident should also get "Resolved"
How to achieve this scenario.