Trying to move Email (sys_email) entries when a case is transferred

Inactive_Us2053
Giga Contributor

Hi,

  I've been asked to try and move associated emails with a General Case to the transferred case.  I've put a business rule in place which should do this.  It looks like it works when looking at the sys_email table, but doesn't show up in the activity list of the new task.  I have made sure that the sent/received emails is in the activity list for the form and that the user I am viewing the form with has the appropriate role to see sent and received emails.

// OnAfter 'insert' business role on sn_hr_core_case
// Condition 'Transferred from' is not empty

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

	var email = new GlideRecord('sys_email');
	email.addQuery('instance', current.transferred_from.sys_id);
	email.query();
	while(email.next()) {
		email.instance = current.sys_id;
		email.target_table = current.sys_class_name;
		email.update();
	}

})(current, previous);

Old pre-transferred case, showing email:

Sys_email entry for above:

Transfer case:

No email in Activity list 😞

But the sys_email entry has been updated by the business rule:

6 REPLIES 6

Cristian Catana
Kilo Explorer

Hi Peter,

 

I was just wondering if you got this working in the end ...

We have a similar requirement to move associated emails when transferring HR cases.

 

Thanks and regards,

Chris C.

Rob Sestito
Mega Sage

Hey Peter,

Not sure if you have found a solution for yourself.

Also, not sure if I am reading your requirement correctly. Are you saying that you need any emails sent to the Original General Case, to be sent to the New Transferred Case post transfer?

If so, you could use this BR that works for us as we needed the same requirement, just in case the end user emailed back to the original General HR Case after we transferred the General Case into the correct COE/HR Service.

When to Run:

find_real_file.png

Script:

(function executeRule(current, previous /*null when async*/) {
	
	var grHRCase = new GlideRecord('sn_hr_core_case');
	
	if (!grHRCase.get(current.transferred_to)) {
		return;
	}
	
	var openingComment = gs.getMessage('Case was cancelled and transferred to {0}', grHRCase.number);
		
		if (current.comments != openingComment) {
			if (current.comments) {
				
				grHRCase.comments = gs.getMessage("{0}\n\n(Copied from original case: {1})", [current.comments, current.number]);
				}
				if (current.work_notes) {
					
					grHRCase.work_notes = gs.getMessage("{0}\n\n(Copied from original case: {1})", [current.work_notes, current.number]);
					}
					grHRCase.update();
				}
			})
			(current, previous);

 

Hope this helps (hopefully I understood your requirement correctly).

Cheers!

-Rob

Roshani
Tera Expert

Hi Peter,

 

Please let us know , how you are able to fix this, as I have a similar requirement. 

Hi, I used to use the business rule that I put in the original post (was sharing the fix that I used).  More recently ServiceNow have added a toggle to HR Case Management where you can use the original case number and record when transferring a case, which makes things far simpler.

Check the table sn_hr_core_transfer_case_config and set 'Reclassify' to be active and default.