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?

17 REPLIES 17

Here's the exact script I used and its still not working: 

 

(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.info("HR Case BR Called");

var notes = "";

// Pull work notes from the HR Case
var jn = new GlideRecord('sys_journal_field');
jn.addQuery('name', 'sn_hr_core_case'); // HR Case table name
jn.addQuery('element', 'work_notes');
jn.addQuery('element_id', current.sys_id);
jn.orderBy('sys_created_on');
jn.query();

while (jn.next()) {
notes += jn.value + "\n\n";
}

// Update related Interaction record(s)
var it = new GlideRecord('interaction');
it.addQuery('hr_case', current.sys_id); // field linking interaction to HR Case
it.query();
while (it.next()) {
it.work_notes = notes;
it.update();
}

gs.info(":Notes = " + notes);
})(current, previous);

Hi @tworzala ,

 

Please check that you are querying to correct record, try to add logs in while of jn glide record,

gs.info(":Notes = " + notes); are you getting the value in this log or not ? 

 

(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.info("HR Case BR Called");

var notes = "";

// Pull work notes from the HR Case
var jn = new GlideRecord('sys_journal_field');
jn.addQuery('name', 'sn_hr_core_case'); // HR Case table name
jn.addQuery('element', 'work_notes');
jn.addQuery('element_id', current.sys_id);
jn.orderBy('sys_created_on');
jn.query();

while (jn.next()) {
gs.info("Inside While =  " + jn.value);
notes += jn.value + "\n\n";
}

// Update related Interaction record(s)
var it = new GlideRecord('interaction');
it.addQuery('hr_case', current.sys_id); // field linking interaction to HR Case
it.query();
while (it.next()) {
gs.info("Inside Whilw 22 ");
it.work_notes = notes;
it.update();
}

gs.info(":Notes = " + notes);
})(current, previous);

 

Check logs that I added in the script 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

I see all the info logs except inside whilw22 and none of the work notes are visible on the HR case.

Hi @tworzala ,

 

On interaction table do you have the field called hr_case? if yes then check current.sys_id contains hr_case's sysId, only in this case it will go inside while.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

Ok, no we don't have the hr_case field on the interaction table. Makes sense then.

 

The rule still isn't working to copy though. ANy other ideas?