i have a button on a custom record that is used to...
# suitescript
p
i have a button on a custom record that is used to print an advanced pdf. one of the fields on the custom record is an image field and this is shown in the pdf. The issue I am having is that using a userEvent (button), clientscript and suitelet to print the advancedPDF gives me the following error:
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "USER_ERROR",
  "message": "Error Parsing XML: The reference to entity \"c\" must end with the ';' delimiter.",
  "id": "",
  "stack": [
    "createError(N/error)",
    "onRequest(/SuiteScripts/sl_printAdvancedPdf.js:24)"
  ],
  "cause": {
    "type": "internal error",
    "code": "USER_ERROR",
    "details": "Error Parsing XML: The reference to entity \"c\" must end with the ';' delimiter.",
    "userEvent": null,
    "stackTrace": [
      "createError(N/error)",
      "onRequest(/SuiteScripts/sl_printAdvancedPdf.js:24)"
    ],
    "notifyOff": false
  },
  "notifyOff": false,
  "userFacing": false
}
If i instead make the advanced PDF the default template for the custom record (which I do not want to do) it works and the image is printed. If I have the image field blank the pdf prints via the userEvent created button. Any ideas how to fix this? Below is my suitelet:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/render', 'N/file', 'N/log', 'N/record'], function(render, file, log, record) {
    function onRequest(context) {
        var recId = context.request.parameters.recId;

        if (recId) {
            // Ensure recId is treated as a number
            recId = parseInt(recId, 10);

            // Load the record
            var rec = record.load({
                type: 'customrecord_show',
                id: recId
            });

            // Create the renderer
            var renderer = render.create();
            renderer.setTemplateById(341);
            renderer.addRecord('record', rec);

            var pdfFile = renderer.renderAsPdf();

            context.response.writeFile({
                file: pdfFile,
                isInline: true
            });
        } else {
            context.response.write('Record ID not provided.');
        }
    }

    return {
        onRequest: onRequest
    };
})
in general, be careful about the escapes (especially the older deprecated way), netsuite automatically escapes when it uses its printing related methods
while not doing the same thing when you create your own renderer
👍 1
p
👍
👍 1