Print PDF Template for Customer Refund – Button click

First create a new template from advanced PDF/HTML Templates then use it in the suitelet

define([‘N/record’, ‘N/render’, ‘N/log’, ‘N/file’, ‘N/log’], 

  function(record, render, file, log) {

  function onRequest(context) {

    if (context.request.method === ‘GET’) {

      var refundId = context.request.parameters.refundid;

      var refundRecord = record.load({

        type: record.Type.CUSTOMER_REFUND,

        id: refundId,

        isDynamic: true

      });

      var renderer = render.create();

      renderer.templateContent = file.load({id: ‘your_custom_template_file_id’}).getContents();

      renderer.addRecord({templateName: ‘record’, record: refundRecord});

      var pdfFile = renderer.renderAsPdf();

      // Set the response content type to PDF

      context.response.contentType = ‘PDF’;

       

      // Return the PDF to the user

      context.response.write(pdfFile.getValue());

    }

  }

  return {

    onRequest: onRequest

  };

});

Leave a comment

Your email address will not be published. Required fields are marked *