Update child Incident Worknotes and comments

Research
Tera Guru

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);

 

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@Research In order to copy work notes to child incident, add a onAfter update business rule as follows.

Screenshot 2023-04-26 at 11.59.17 PM.pngScreenshot 2023-04-27 at 12.00.09 AM.png

 

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.

View solution in original post

@Sandeep Rajput 

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

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Research In order to copy work notes to child incident, add a onAfter update business rule as follows.

Screenshot 2023-04-26 at 11.59.17 PM.pngScreenshot 2023-04-27 at 12.00.09 AM.png

 

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.

@Sandeep Rajput 

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

This script is already taking care of copying the parent work notes on child incidents. If the child incidents have further children then it will copy the worknotes on them as well.

 

Also, instead of marking my answer correct, you have marked your own reply as correct. Please mark my initial response as correct and helpful. 

@Sandeep Rajput 
concern is parent incident state changes like (in progress, on hold, resolved, closed) same should change in child as well like worknotes 
can we add the script for this in above BR 

Thankyou