Generate PDF as a formatted page and send email

Chris York
Tera Expert

My goal is to have a easy way to take a record (It happens to be a Purchase Order record in a custom PO table) in ServiceNow and generate a formatted page (including image tags + other html formatting) and then generate a PDF file from that page and then send that PDF file to an email address

Step 1 - Generate a formatted page. I think the best way for this is a custom UI Page.
Step 2 - Create a PDF file for this page (similar to what happens when you export a page to PDF).
Step 3 - Send that PDF file in an email to an external vendor address that is contained on the original PO record in ServiceNow.

Ideally this would all be a one-click operation from the PO record.

Any thoughts or ideas how I could accomplish this requirement?

12 REPLIES 12

Stig Brandt2
Mega Expert

I'm having the same requirements for a customer, is this possible ?

1) generate a pdf file
2) attach to a record

from a script

thanks in advance


jquinonez
Tera Contributor

Yes, I'm sure this is possible, as I've heard others are doing it.   I also have this requirement.   I understand their are some options such as using Office or Excel to pull in data, but really need to provide this feature for our staff.   I'm getting more of these types of requests the more we use ServiceNow and especially when we add new custom applications.   I certainly will share if I come across any information.


luke_kelly
Kilo Explorer

I use this, but I dont think it works in dublin (havent tested yet) but im fairly confident it doesnt.




The problem is that the package removal tool cannot replace Packages.com.glide.generators.PDFGenerator() and packages cant be used anymore




function addAttachmentToEmail(sysEmailRec) {


try {


var targetTable = new String(sysEmailRec.target_table);


var targetSysId = new String(sysEmailRec.instance);



// Retrieve the record for the attached item


var targetRec = new GlideRecord(targetTable);


if (targetRec.get(targetSysId)) {



var pdfGenerator = new Packages.com.glide.generators.PDFGenerator();



pdfGenerator.setTarget(targetTable);


pdfGenerator.setSysID(targetSysId);


pdfGenerator.setList(false);


pdfGenerator.setDetails(true);


pdfGenerator.setLandscape(false);



var outStream = new Packages.java.io.ByteArrayOutputStream();


pdfGenerator.generate(outStream);




// Sys attachment creation


var sysAttachment = new Packages.com.glide.ui.SysAttachment();


var attID = sysAttachment.write(sysEmailRec, targetRec.getDisplayValue() + '.pdf', 'application/pdf', outStream.toByteArray());


}


} catch (ex) {



}


}






Ill post back if I workout how to change this to work in dublin


Hey Luke,



Did this work is later versions like eureka,Fuji,Geneva and Helsinki??


krempe
Mega Contributor

Hi Chris, did you ever get a resolution?   I need something similar for a custom app.   I was directed to:


 


Using PDFCrowd to generate a PDF file from ServiceNow.



http://www.john-james-andersen.com/blog/service-now/custom-pdf-files-in-servicenowthrough-pdfcrowd.h...




I have no idea how to actually do it or use it but as I read, it will address your Step 2.


K