- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2023 10:20 AM - edited 04-26-2023 10:21 AM
Hi
I have a requirement to update child incident when parent incident is updated we have OOTB functionality working for comments and work notes but its not working.
Previously did any one implemented let us know please.
Do we have any other alternative way to code in below script to add work notes and comments in below script
Thanks.
/**
* @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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2023 11:32 AM
@Community Alums In order to copy work notes to child incident, add a onAfter update business rule as follows.
Here is the script for the business rule.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
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()) {
grIncident.work_notes = current.work_notes.getJournalEntry(1);
grIncident.update();
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 12:04 PM - edited 04-27-2023 12:04 PM
Thankyou very much for the solution it helped for my requirement
for the below script can we add the code (if state changes in parent)
same should replicate in child ticket
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
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()) {
grIncident.work_notes = current.work_notes.getJournalEntry(1);
grIncident.update();
}
})(current, previous);Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If I update the task worknotes it should update RITM worknotes