Copy Child Incident Worknotes to parent

Mark Wood
Tera Contributor

Hello Team,

I would like to copy the latest work notes from a child incident to its parent incident. I have configured an "After Insert and Update" Business Rule that runs only when the parent incident is not empty and the work notes field is changed.

In the Business Rule, I have written a script to update the work notes of the parent incident. However, I'm facing an issue where I'm unable to access the latest work note—it is returning as undefined.

Could you please guide me on how to correctly retrieve the latest work note in this scenario?

Thank you!

 

(function executeRule(current, previous /*null when async*/) {



gs.addInfoMessage(gs.isInteractive());

var parentInc = new GlideRecord('incident');
parentInc.addQuery('sys_id', current.parent_incident); // Get parent incidents of the current record
parentInc.query();
gs.addErrorMessage("Line 8");
while (parentInc.next()) {
gs.addErrorMessage('If block'+current.getJournalEntry(-1));//giving undefined

    parentInc.work_notes = current.getJournalEntry(1); // Copy the latest journal entry to parent
    parentInc.setWorkflow(false);
	parentInc.update();

}
})(current, previous);
3 REPLIES 3

Robert H
Mega Sage

Hello @Mark Wood ,

 

Please replace

parentInc.work_notes = current.getJournalEntry(1)

With this:

parentInc.work_notes = current.work_notes.getJournalEntry(1)

 

Regards,

Robert

Rohit  Singh
Mega Sage

Hi @Mark Wood ,

 

You missed the name of field while assigning the value to the work notes of your parent incident. As correctly mentioned by @Robert H 

Use this :

 

parentInc.work_notes = current.work_notes.getJournalEntry(1);

 

setWorkflow(false) - this will stop the trigger of any other workflow,flow,be to trigger once your work notes is updated in incident table. So use it is really required as per use case.

 

If my response helped, please mark my response as solution accepted and hit thumbs up.

 

Regards,

Rohit

Hi @Mark Wood ,

 

Glad that my response was helpful. 

Please also mark my response as solution expected so that it help future reader as well.

 

Regards,

Rohit