Copy email history from original HR case on the transferred HR case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
The requirement is that - full email history to transfer with an HR case when it is reassigned or recategorized (transferred), so that all communications related to the case remain visible, accurate, and centralized in one record. I am trying to consolidate the email logs from the original case and print them in work notes using a business rule.
Table: HR Case [sn_hr_core_case]
When to run: After insert, Transferred from is not empty AND Transferred from changes.
I am open to any suggestions on how it could be done in any other/better way as well.
Thanks much in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi Arpita,
If both solutions are not working, the issue is likely deeper than the script logic itself. Let us troubleshoot systematically.
Step 1: Verify the Business Rule is actually firing
Add this as the very first line inside the function and check your system logs:
gs.info('AK07 BR fired - current sys_id: ' + current.sys_id + ' transferred_from: ' + current.getValue('transferred_from'));If you do not see this in the logs, the Business Rule is not firing at all, which means the condition is the problem not the script.
Step 2: Verify emails actually exist in sys_email for the old case
Run this in Scripts Background replacing the sys_id with your actual old case sys_id:
var emailGr = new GlideRecord('sys_email');
emailGr.addQuery('instance', 'YOUR_OLD_CASE_SYS_ID');
emailGr.query();
gs.info('Email count: ' + emailGr.getRowCount());
while (emailGr.next()) {
gs.info('Email found: ' + emailGr.subject + ' | target_table: ' + emailGr.target_table);
}This will tell you two things: whether emails are actually linked to the old case via the instance field, and what the target_table value looks like so you can match it exactly in your query.
Step 3: Check the Business Rule trigger timing
The requirement says After Insert with transferred_from changes. But when a case is transferred in HR Service Delivery, the new case is created as a fresh insert. At the time of insert, ServiceNow may not recognise transferred_from as "changed" since there is no previous value to compare against on an insert operation.
Try changing your condition to simply:
!gs.nil(current.getValue('transferred_from'))And set the Business Rule to run on Insert only without the changes() condition.
Can you share what the system logs show after adding the Step 1 logging line? That will tell us exactly where the process is breaking down.
ServiceNow Developer & Admin
Builder of NowFixer | Free AI debugging tool for ServiceNow scripts
