Pull a pdf attachment into an email containing change info (pdf generator)

Pre-requisite

the PDF generator needs to be installed in the instance

 

this can be installed from plugins I believe:


Business rule

 

 

(function executeRule(current, previous /*null when async*/) { var chg = new GlideRecord(current.target_table); chg.get(current.instance); if (chg.isValidRecord()) { var br = '<br/><br/>'; // Line breaks var html_content = '<h3>' + 'Number: ' + chg.number + br + 'Type: ' + chg.getDisplayValue('type') + br + 'State: ' + chg.getDisplayValue('state') + br + 'Service Offering: ' + chg.service_offering.name + br + 'Category: ' + chg.category + br + 'Priority: ' + chg.getDisplayValue('priority') + br + 'Outage Start Time: ' + chg.u_outage_start_date_time + br + 'Outage End Time: ' + chg.u_outage_end_date_time + br + '</h3>'; file_name = current.subject + '.pdf'; target_record_table = current.getTableName(); target_record_sys_id = current.getUniqueValue(); new si_PDF_Generator().generatePDF(html_content, file_name, target_record_table, target_record_sys_id); } })(current, previous);

 

script include

var si_PDF_Generator = Class.create(); si_PDF_Generator.prototype = Object.extendsObject(AbstractAjaxProcessor, { generatePDF: function(html_content, file_name, target_record_table, target_record_sys_id) { if (html_content == undefined) html_content = this.getParameter('sysparm_html_content'); if (file_name == undefined) file_name = this.getParameter('sysparm_file_name'); if (target_record_table == undefined) target_record_table = this.getParameter('sysparm_target_record_table'); if (target_record_sys_id == undefined) target_record_sys_id = this.getParameter('sysparm_target_record_sys_id'); var document = null; var pdfDoc = new GeneralPDF.Document(null, null, null, null, null, null); document = new GeneralPDF(pdfDoc, null, null); document.startHTMLParser(); document.addHTML(html_content); document.stopHTMLParser(); var att = new GeneralPDF.Attachment(); att.setTableName(target_record_table); att.setTableId(target_record_sys_id); att.setName(file_name); att.setType('application/pdf'); att.setBody(document.get()); GeneralPDF.attach(att); }, type: 'si_PDF_Generator' });


Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage

variable advanced reference qualifier example