Copy work notes from interaction to associated HR Case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @tworzala ,
I try to find new script please check below details
Create before BR, table - Interaction, Advance - true, Insert and update - true, add below code
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
gs.info("BR Called");
if (!current.opened_for) {
gs.info("Interaction has no opened_for, skipping HR Case sync.");
return;
}
// Get the newly added journal entry
var newNote = current.work_notes.getJournalEntry(1);
if (!newNote) {
return;
}
var hr = new GlideRecord('sn_hr_core_case');
hr.addQuery('opened_for', current.opened_for);
hr.orderByDesc('sys_created_on');
hr.query();
if (!hr.next()) {
gs.info("No HR Case found for opened_for: " + current.opened_for);
return;
}
var hrUpdate = new GlideRecord('sn_hr_core_case');
if (hrUpdate.get(hr.sys_id)) {
hrUpdate.work_notes = newNote +
"\n\n-- Copied from Interaction: " + current.number;
hrUpdate.update();
gs.info("Copied Interaction work note to HR Case: " + hr.number);
}
})(current, previous);
Result
Worknotes on Interaction table
Got copied to HR table
Let me know if you need any help!
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Its copying something now but only the piece where the HRC has been created from xx interaction, which is already there anyways. It didn't bring any of the other notes from the interaction over. See my screenshots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
See my latest screenshots. Its still not working but seems close.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @tworzala,
You can create a business rule. Please take a look at the script below, the smartest one, haha
Table: sn_hr_core_case
When: after insert
Condition: current.interaction is not empty
(function executeRule(current, previous /*null when async*/) {
if (!current.interaction)
return;
var inter = new GlideRecord('interaction');
if (inter.get(current.interaction)) {
// Copy the latest work_notes entry to the HR case as a new work note
if (inter.work_notes) {
current.work_notes = inter.work_notes;
current.update(); // one extra update right after insert
}
}
})(current, previous);
Hope it helps,
Best regards,
Renat Akhmedov
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
How do I add the Condition: current.interaction in the filter condition. I can't find anything related to interaction in the dropdown.
