The CreatorCon Call for Content is officially open! Get started here.

why "GeneralPDF" not working, getting error like GeneralPDF not defined

Sironi
Kilo Sage

Hi All,

Kindly let me know why GeneralPDF not working

Error

gs.addErrorMessage("PDF generation failed: " + e.message);

GeneralPDF not defined.

Client SCript :

var responseBody = Contenthtml;
var letterheadHTML =
        "<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
        "xmlns:w='urn:schemas-microsoft-com:office:word' " +
        "xmlns='http://www.w3.org/TR/REC-html40'>" +
        "<head><meta charset='utf-8'></head>" +
        "<body>" +
        "<div style='font-family: Calibri, sans-serif; padding: 40px; line-height: 1.6;'>" +

        "<div style='text-align: right; margin-bottom: 30px;'>" +
        "<img src='https://dev351275.service-now.com/customer_service_email_logo.png' style='width: 100%; max-height: 120px;' alt='Header Image'>" +
        "</div>" +

        "<div>" +
        "<p><strong>Date:</strong> " + new Date().toLocaleDateString() + "</p>" +
        responseBody +
        "</div>" +

        "<div style='text-align: center; margin-top: 50px;'>" +
        "<img src='https://dev351275.service-now.com/customer_service_email_logo.png' style='max-height: 80px; max-width: 300px;' alt='Footer Image'>" +
        "</div>" +

        "</div>" +
        "</body>" +
        "</html>";


var ga2 = new GlideAjax('global.AttachToRecord');
    ga2.addParam('sysparm_name', 'getPDF');
    ga2.addParam('sysparm_recordSysId', taskSysId);
    ga2.addParam('sysparm_tableName', tableName);
    ga2.addParam('sysparm_htmlContent', letterheadHTML);
    ga2.addParam('sysparm_ filename', 'Welcome.pdf');
    ga2.getXMLAnswer(function(response) {
        alert('PDF Attachment created successfully!');
    });

 

Script Include : GeneratingPDF(custom)

var GeneratingPDF = Class.create();
GeneratingPDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getPDF: function() {
       var table = this.getParameter('sysparm_tableName');
       var sysId = this.getParameter('sysparm_recordSysId');
       var htmlContent = this.getParameter('sysparm_htmlContent');
       var filename = this.getParameter('sysparm_ filename');

        this.createPDF(htmlContent, table, sysId, filename); 
    },
    createPDF: function(html, table, sys_id, filename) {
        var pdfDoc = new GeneralPDF.Document(null, null, null, null, null, null);
        this._document = new GeneralPDF(pdfDoc);
        this._document.startHTMLParser();
        this._document.addHTML(html);
        this._document.stopHTMLParser();
        this._saveAs(table, sys_id, filename);
    },
    _saveAs: function(table, sys_id, filename) {
        var att = new GeneralPDF.Attachment();
        att.setTableName(table);
        att.setTableId(sys_id);
        att.setName(filename);
        att.setType('application/pdf');
        att.setBody(this._document.get());
        GeneralPDF.attach(att);
    },
    type: 'GeneratingPDF'
});

 

 

8 REPLIES 8

MPD Odijk
Tera Expert
  1. Does the Script Include exist? https://<instance>.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=dcc5ee1137102100904961...
    1. If yes: is it customized?
  2. Is your Custom Script "global"?
    1. If not: GeneralPDF is not accessible from a scoped applocation by default, so you would have to adjust that AND use "global." as a prefix OR make sure that your custom Script Include is in the global scope.
  3. Ankur Bawiskar is not wrong, but I think it depends on the amount of custom work that you already have in place before deciding to move.

Good luck!

Hi @MPD Odijk , thanks for your reply.

"GeneralPDF" is OOB Script-Include, not custom one . Earlier it used to work very nice way. not this OOB script-include not existed in system also. Not sure what wrong happened there.

Dinesh Patel
Tera Contributor

 

please use latest PDFGeneration API

PDFGenerationAPI - Scoped, Global 

Generating Custom PDFs - using the new PDFGenerationAPI 

If my response helped please mark it correct and close the thread so that it benefits future readers

--------------------------------------------------------------------------------------------------------------------------------------------------
If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful. Let me know if anything else is required.

Thanks,
Dinesh Patel

kaushal_snow
Mega Sage

Hi @Sironi ,

 

The error GeneralPDF not defined means that ServiceNow can’t find the GeneralPDF Script Include in your instance at runtime. That can happen if:

 

The OOTB GeneralPDF script include has been removed or disabled in your version....The plugin that provided it is not installed or not active....Your code scope doesn’t allow access to it (especially in scoped apps or restricted scopes)......

 

ServiceNow now recommends using PDFGenerationAPI (part of the PDF Generation Utilities plugin) instead of GeneralPDF. It’s more supported and likely will work in modern releases.....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/