RE: How to render sales order and picking ticket advanced pdf from a custom button?

I have created suitelet script to render sales order advanced pdf. Now I want to combine the picking ticket on second page of sales order pdf. Sales order pdf template is sales order type and picking ticket pdf template  is ‘picking ticket’ type it could be possible? I will appreciate your help!

/**

 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define([‘N/search’, ‘N/record’, ‘N/runtime’,’N/render’,’N/file’,’N/url’,’N/xml’],
function(search, record, runtime,render,file,url,xml)
{
  function onRequest(context) {
      try{
          var requestparam = context.request.parameters;
          var custom_id = requestparam.recId;
          log.debug(“custom_id”,custom_id);
          //var custom_id=13187;
          var pdfFileName = “salesorder”;
          var renderer = render.create();
          renderer.setTemplateByScriptId(“CUSTTMPL_514_7621183_SB1_505”);
                  var content = renderer.addRecord({
                templateName: ‘record’,
                record: record.load({
                  type: record.Type.SALES_ORDER,
                  id: custom_id
                })
              });
          context.response.setHeader({
            name: ‘content-disposition’,
            value: ‘inline; filename=”‘ + pdfFileName + ‘_’ + custom_id + ‘.pdf”‘
          });
                              //resolve domain to get suitelet url
          var output = url.resolveDomain({
              hostType: url.HostType.APPLICATION,
          });
          log.debug(“output”,output);
          var pdfFileObj=renderer.renderAsPdf();
          log.debug(“pdfFileObj”,pdfFileObj);
          pdfFileObj.folder = 1797;
          pdfFileObj.name = “samplepdf”;
          pdfFileObj.isOnline = true;
          // log.debug(“bol”, bol);
          let fileid = pdfFileObj.save();
          log.debug(“fileid”,fileid);
           //loaded the pdf files
               let pdfFinal1 = file.load(fileid);
               output = “https://” + output + pdfFinal1.url;
               log.debug(“output”,output);
               context.response.write(
                  `<html><head><script>window.open(“${output}”)</script></head></html>`
                );
                 }
      catch(e)
      {
          log.debug(“error”,e);
      }
      context.response.write(
          `<html><head><script>window.close()</script></head></html>`
        );
  }
       return {
       onRequest:onRequest
    };
});
Maira S Beginner Asked on January 5, 2024 in SuiteScript.
Add Comment
1 Answers

Create the button with SUE then have it call a function in the CUE to capture all the data and pass it to the suitelet to render the pdf

Rookie Answered on January 18, 2024.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.