A while back I had a weird use case where I needed an incoming reply from an outbound e-mail notification to be attached to a different record than the notification had originated from. I was working with two record types with a one-to-many parent/child relationship. I needed to trigger an outgoing e-mail whenever a child record was created, but the stakeholders wanted the audit trail of all outgoing e-mail to live at the parent level, and they wanted replies coming back from those outgoing e-mails to also be attached to the parent record instead of the child.

So I went ahead and created my outbound e-mail notifications at the child level, then I wrote two business rules to diddle with the e-mail records and the watermarks. One business rule moves the e-mail records so they show up at the parent level instead of the child. The other business rule modifies the watermarks so all incoming reply e-mails will be routed to the parent record instead of the child.

(My use case involved custom tables, but in the code below I’ll use Requested Item and Catalog Task as examples. You can obviously modify this to work with any two tables you wish.)

Diddling with e-mails

Table: Email [sys_e-mail]
When: before
Insert: no
Update: yes
Condition: current.target_table == 'sc_task' && current.type == 'sent'

Script:

(function executeRule(current, previous /*null when async*/) {
    // Move this e-mail to the Catalog Task's parent Requested Item record
	var gr = new GlideRecord('sc_task');
	if (gr.get(current.instance)) {
		current.target_table = 'sc_req_item';
		current.instance = gr.getValue('request_item');
	}
})(current, previous);

Diddling with watermarks

Table: Watermark [sys_watermark]
When: before
Insert: yes
Update: yes
Condition: current.source_table == 'sc_task'

Script:

(function executeRule(current, previous /*null when async*/) {
    // Move this watermark to the Catalog Task's parent Requested Item record
	var gr = new GlideRecord('sc_task');
	if (gr.get(current.source_id)) {
		current.source_table = 'sc_req_item';
		current.source_id = gr.getValue('request_item');
	}
})(current, previous);

This was an unique use case I’ve only ever encountered once, but diddling with the watermarks was a fun solution I’m definitely keeping in my back pocket for future use.