- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 10:14 PM
I have a business requirement of generating the GRC Policy Exception record as PDF and attach the document in Policy Exception approval emails. as there is no direct way of doing this, based on a forum article, I created a HTML template in 'Document Templates" module.
Then, I created a record in script includes as follows
var PolicyExceptionPDFGenerator = Class.create();
PolicyExceptionPDFGenerator.prototype = {
initialize: function() {},
generatePDF: function(recordSysId) {
var gr = new GlideRecord('sn_compliance_policy_exception');
if (gr.get(recordSysId)) {
var htmlTemplate = GlideSysAttachment.getContentStream(gr.sys_id, '0f48ac2cf0df121070bd59e0c86bba81');
var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();
var pdf = pdfAPI.convertToPDF(htmlTemplate, 'sn_compliance_policy_exception', recordSysId, 'Policy_Exception_Report.pdf');
return pdf;
}
return null;
},
attachPDFToRecord: function(recordSysId, pdf) {
var gr = new GlideRecord('sn_compliance_policy_exception');
if (gr.get(recordSysId)) {
var attachment = new GlideSysAttachment();
attachment.write(gr, 'Policy_Exception_Report.pdf', 'application/pdf', pdf);
}
},
type: 'PolicyExceptionPDFGenerator'
};
Then i created a business rule on policy exception table that triggers when the State change to Awaiting Approval
(function executeRule(current, previous /*null when async*/) {
var pdfGenerator = new PolicyExceptionPDFGenerator();
var pdf = pdfGenerator.generatePDF(current.sys_id);
if (pdf) {
pdfGenerator.attachPDFToRecord(current.sys_id, pdf);
}
})(current, previous);
But when i am trying to generate the approvals, I noticed that this is not getting attache to the record.
Any idea what is missing here?
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
__PRESENT
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 10:55 PM
are you having a requirement to include the PDF in particular look and feel?
If yes then only use Document template
If not then you can create a form view consisting of fields you want and then refer below link to generate the pdf and attach to record,
Generate PDF and attach to the record
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 10:55 PM
are you having a requirement to include the PDF in particular look and feel?
If yes then only use Document template
If not then you can create a form view consisting of fields you want and then refer below link to generate the pdf and attach to record,
Generate PDF and attach to the record
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 10:59 PM
you can use this script to attach
(function executeRule(current, previous /*null when async*/) {
var recordId = current.sys_id;
var pdfName = 'Policy_Exception_Report.pdf';
var documentTemplateId = '''; // give sysId of that document template
new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 01:02 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2025 08:45 PM
Yes. I have the requriement to generate the PDF with certain look and feel (Header Logos, Tables, Alignments and etc). Therefore, I need to use Document Template. I will try the script and respond back today