Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

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?

6 REPLIES 6

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
Giga 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

ajmalmuhamm
Tera Contributor

Hi @RabindraK,

Yes, this is possible. If the PDF is already attached to the Risk record, you can configure your Email Notification to include record attachments so the PDF is sent automatically to senior management.

If the PDF needs to be generated dynamically, you can use Document Generation (or a Document Template) together with Flow Designer to generate the PDF, attach it to the Risk record, and then trigger the email notification with the generated PDF attached.

This approach keeps the process automated and ensures senior management receives the latest version of the report without any manual intervention.

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.