Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy work notes from interaction to associated HR Case

tworzala
Tera Contributor

When creating a new HR case on an interaction, I'm trying to get the work notes from the interaction to copy over to the new HR Case that's associated. I'm trying to create a business rule but not having luck. Can anyone help?

3 REPLIES 3

JoaoFurtado
Tera Expert

Hi @tworzala , hope your doing well!

Found this article that could help you!
Solved: How to copy worknotes from interaction to Incident... - ServiceNow Community

Gangadhar Ravi
Giga Sage

@tworzala Can you please share script you have in your BR.

Here's the latest script I was trying. The BR is on the HR case after insert.

 

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

// Find any interactions linked to this HR Case via interaction_related
var irGR = new GlideRecord('interaction_related');
irGR.addQuery('related_record', current.sys_id); // HR case is the related record
irGR.addQuery('parent.table', 'interaction'); // Ensure parent is an interaction
irGR.query();

var notesToAdd = '';

while (irGR.next()) {
var interaction = new GlideRecord('interaction');
if (interaction.get(irGR.parent.sys_id)) {

if (interaction.work_notes) {
// Append each interaction's notes with separator
notesToAdd += (notesToAdd ? '\n' : '') + interaction.work_notes;
}
}
}

// Only update the HR case if there are notes to add
if (notesToAdd) {
var existing = current.work_notes || '';
current.work_notes = existing ? existing + '\n' + notesToAdd : notesToAdd;
current.update(); // safe to update because this is After Insert
}

})(current, previous);