Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

generating PDF attachment and sending via email notification

RabindraK
Tera Contributor

how to attach some PDF records in email notifications to senior management in risk management in ServiceNow?

4 REPLIES 4

Tanushree Maiti
Tera Patron

Hi @RabindraK 

 

Refer ServiceNow Documentation : Document attachments on an email notification 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ehab Pilloor
Mega Sage

Hi @RabindraK,

 

You can attach documents and reports to email notifications by scripting or linking to the sys ID of the record.

You can include all attachments from the source record with the notification. For example, if an incident update generates a notification, you can include all attachments from the incident record with the notification. To include all attachments from the source record, go to Advance view and select the check box for the Include attachments under What will it contain tab. The email messages, including attachments, cannot exceed the maximum email size. This size includes MIME encoding. For details on MIME encoding, see Email service size restrictions.

Attaching documents with scripting

Using scripting, you can attach documents by linking to them, or you can attach various types of reports by specifying their IDs in the system.

Linking to an attachment

You can add an attachment to a notification by linking to the attachment record in the message of the notification. Upon clicking the link, email recipients log in to the instance to view the attachment record.

Linking to attachment records in this fashion requires using email notification scripting. For example:
template.print ( 'Attachment: <a href="/sys_attachment.do?sys_id=' + now_GR. sys_id + '">' + now_GR. file_name + '</a>\n ' ) ;

Attaching reports using the Sys ID

You can also attach various types of reports, including gauges, dashboards, and charts, to a notification. The scripts to attach these reports take the following syntax:
${report:X:Y}
where:

X is the type of report you want to attach (reportID, gaugeID, dashboardID, or chartID).

Y is the sys ID of the report, gauge, dashboard, or chart to be attached.

For example:
  • ${report:reportID:<abc123>}
  • ${report:gaugeID:<abc123>}
  • ${report:dashboardID:<abc123>}
  • ${report:chartID:<abc123>}
Note:
Multilevel pivot reports can’t attach to email notifications.

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

yashkamde
Giga Sage

Hello @RabindraK ,

 

try this approach for generating pdf using template :

Use this script inside your server script auto-creates a sys_attachment record against current..

var pdfGenerator = new sn_communications.PDFGeneratorAPI();
var renderResult = pdfGenerator.convertUiPageToPDF(
    'your_ui_page_name',   // Jelly UI page defining the PDF layout
    'sysparm_id',
    current.sys_id,
    current.getTableName()
);

 

Then attach this as a Mail Script under the notification's What it will contain

(function runMailScript(current, template, email, email_action, event) {
    var att = new GlideRecord('sys_attachment');
    att.addQuery('table_name', current.getTableName());
    att.addQuery('table_sys_id', current.sys_id);
    att.addQuery('content_type', 'application/pdf');
    att.orderByDesc('sys_created_on');
    att.setLimit(1);
    att.query();
    if (att.next()) {
        email.addAttachment(att);
    }
})(current, template, email, email_action, event);

 

If my response helped mark as helpful and accept the solution.

Ankur Bawiskar
Tera Patron

@RabindraK 

are you trying to send some report to senior management?

what that PDF should contain? which records and from which table and what condition?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader