How to use email layout/templates on Scheduled reports?

JC S_
Mega Guru

We want the email body of the scheduled report to utilize our email layout which contains our company branding. We can already do this for all email notifications we have set in the system.

We can manually copy the layout HTML code on the report_body of Scheduled Report but this will be tedious and will not be flexible in the long run in case we need to update our company branding (we have to manually update each scheduled report if ever). Any ideas?

 

SOLUTION UPDATE:

I evolved the solution provided below so that it can be applied selectively (not all outbound emails). Please check out this article wherein I detailed the approach we took for this issue.

1 ACCEPTED SOLUTION

Gaurav Bajaj
Kilo Sage

Hi,

I was wondering how you have applied the branding in first place for all other emails.

If you have done it by writing a business rule on sys_email table to populate the HTML layout once an email record is inserted, it should also work out for scheduled reports.

 

From the below script. create a email template first and place a  mail string in your template.

find_real_file.png

 

One its done, write a BR on sys_email template.

var gr = new GlideRecord("sysevent_email_template");
if(gr.get("name", "company_signature"))
{
	var signature = gr.message_html;
}

var mybody = signature.replace(/\[mail\]/g, current.body);
current.body = mybody;

 

 

Hope that explains it

 

Thanks

Gaurav

View solution in original post

4 REPLIES 4

Gaurav Bajaj
Kilo Sage

Hi,

I was wondering how you have applied the branding in first place for all other emails.

If you have done it by writing a business rule on sys_email table to populate the HTML layout once an email record is inserted, it should also work out for scheduled reports.

 

From the below script. create a email template first and place a  mail string in your template.

find_real_file.png

 

One its done, write a BR on sys_email template.

var gr = new GlideRecord("sysevent_email_template");
if(gr.get("name", "company_signature"))
{
	var signature = gr.message_html;
}

var mybody = signature.replace(/\[mail\]/g, current.body);
current.body = mybody;

 

 

Hope that explains it

 

Thanks

Gaurav

Thanks for this Gaurav! We are able to evolve this solution and have it selectively apply so that it will not conflict with our existing Email Notifications that use Email Layouts already. You can check out the article I wrote about it.

Gaurav Bajaj
Kilo Sage

Nice explanation of something which everyone needs for their organization 🙂

Thanks! Hopefully it will help others save time implementing their organization branding (I totally agree that everyone should do this - quite simple to implement if you really look at it now)

It took us a while to realize the Email Layout > Email Template > Email Notification connection which is OOB setup in ServiceNow. The only advantage of this setup is we can preview how the notification will look like.

Using a business rule to force insert the email layout does not give us the quick preview capability. Though the business rule option is our only way to apply email layouts on scheduled reports.

Seems like a hassle just to get company branding on emails, hopefully ServiceNow will improve this and make it straight forward on future releases.