var gr1 = new GlideRecord("sys_attachment"); gr1.addQuery("table_sys_id", current.sys_id); gr1.addEncodedQuery("file_nameLIKEtxt"); gr1.query(); if (gr1.next()) { var gsa = GlideSysAttachmentInputStream(gr1.sys_id.toString()); var baos = new Packages.java.io.ByteArrayOutputStream(); gsa.writeTo(baos); baos.close(); var content = baos + ' '; //the break lines were missing so I added this for (var i = 0; i < content.length; i++) { var match = /\r|\n/.exec(content[i]); if (match) { content = content.replace(content[i], '<br>'); } } var html = '<p>' + content + '</p>'; var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI(); var hfInfo = new Object(); hfInfo["FooterText"] = "0001/2022 - v1 de 02-02-2022"; hfInfo["PageSize"] = "A4"; hfInfo["GeneratePageNumber"] = "true"; hfInfo["FooterTextAlignment"] = "BOTTOM_LEFT"; var result = pdf.convertToPDFWithHeaderFooter(html, "sc_req_item", current.sys_id, "s", hfInfo);
Convert text into PDF attachment ServiceNow
admin Changed status to publish December 19, 2023