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.

Omit watermark from scheduled report emails

zheil
Mega Expert

Hi All

 

If I'd like to I omit watermark from scheduled report emails, how can I do that? Unlike in email notifications, there is no omit watermark option in scheduled report emails.

1 ACCEPTED SOLUTION

GRGisMe
Mega Expert

While Chandan's reply was excellent, I don't think it will help in this situation. Scheduled Reports don't go through the Notifications table, and there is no "Omit Watermark" field on the sysauto_report table.



I think the best solution in this case would be to create a "before insert" business rule on the sys_email table, that looks for part of the expected subject line of the scheduled report emails, and then looks for the watermark and removes it.



This would look something like:



Condition:   current.type == 'send-ready' && current.subject.toString().indexOf("Scheduled Execution of") >= 0



Script:


current.body = String(current.body).replace(/Ref\:MSG(?:[0-9]*)/i, "");


current.body_text = String(current.body_text).replace(/Ref\:MSG(?:[0-9]*)/i, "");


View solution in original post

7 REPLIES 7

Would that business rule apply to all existing scheduled reports?



If not, how could I make the watermark disappear from all existing scheduled reports?


Hi



I have created my inbound action on data source table . when i am trying to import the file from mail it telling no watermark matched on schedule report table. since i have removed the watermark still the error is coming. Do we have any way to get rid of this issue.



Regards


Vincent Miedema
Tera Contributor

To somebody looking for a little more current, extended solution to stop the system from matching a reply to the originating Scheduled Report record, you might try this script. In a Before update Business Rule on [sys_email]. 

 

Condition:

current.type == 'send-ready' && current.target_table == 'sysauto_report'

 

Script:

// Watermark is automatically added at end of body and body text. Cannnot be skipped because there's no Omit Watermark checkbox like Notifications have
	// Remove watermark from 'Ref:MSG' until the first '<' encountered. This can be </div> or </body_text>
	// To prevent replies ending up in void of the Scheduled Report record, and instead have them picked up by Email Inbound Actions like our 'Process Inbound Email (Reply)'

	// Example Body
	//  before "<div style="display:inline">Ref:MSG4821783_H4q4i3dfn4Ksit80b8vH</div></body></html>"
	//  after "<div style="display:inline"></div></body></html>"
	current.body = String(current.body).replace(/Ref\:MSG(?:[^<]+)/i, "");
	
	// Example Body Text
	//  before "Best regards, xxx Ref:MSG4821783_H4q4i3dfn4Ksit80b8vH</body_text>"
	//  after "Best regards, xxx </body_text>"
	current.body_text = String(current.body_text).replace(/Ref\:MSG(?:[^<]+)/i, "");
	
	// Clear the Target field
	//   so it can't find Scheduled Report record by matching "In-Reply-To" to "Message-ID" from sent Email and setting the same Target
	//   only correct way to clear a field: https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/script/server-scripting/reference/r_SettingAGlideRecordVariableToNull.html
	current.instance = 'NULL';
	
	// Clear Source Record and Source Table in table [sys_watermark]
	//   so it can't find Source Record (Target) by matching "In-Reply-To" to "Message-ID" from sent Email and getting it from [sys_watermark]
	//   and matching "Source Table" to Email Inbound Actions's "Target Table" doesn't fail, since there's no Inbound Action for [sysauto_report]
	//   [sys_watermark] record is created just before the [sys_email] one so we can already fetch and update it at this point
	var grWM = new GlideRecord('sys_watermark');
	if(grWM.get('email', current.getUniqueValue())){
		grWM.source_id = 'NULL';
		grWM.source_table = 'NULL';
		grWM.update();
	}