Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the custom PDF template while clicking the button

I want to show the PDF Template in new window while clicking the button in Sales Order. I created the button in sales order process using user event script. after that i'm unable to proceed it. It is possible to show the custom PDF template in new window while clicking the sales order?

My CODE:

USER EVENT SCRIPT:

     // creating button in user event script before load event in view mode
        unction userEventBeforeLoad(type, form, request){  


    if(type == 'view'){
         var internalId = nlapiGetRecordId();

            if (internalId != null) {
                var createPdfUrl = nlapiResolveURL('SUITELET', 'customscript_back0rdered_itm_pdf', 'customdeploy_backord_itm_pdf_dep', false);
                createPdfUrl += '&id=' + internalId;

                //---add a button and call suitelet on click that button and it will open a new window
                var addButton = form.addButton('custpage_printpdf', 'Print PDF', "window.open('" + createPdfUrl + "');");
            }
            else {
                nlapiLogExecution('DEBUG', 'Error', 'Internaal id of the record is null');
            }
    }
}


SUITELET SCRIPT:

function suitelet(request, response){
     var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
     xml += "<pdf>";
     xml += "<head><macrolist><macro id=\"myfooter\"><p align=\"center\"><pagenumber /></p></macro></macrolist></head>";
     xml += "<body size= \"A4\" footer=\"myfooter\" footer-height=\"0.5in\">";
     var record = request.getParameter('internalId');
     xml +="record";       //Add values(in string format) what you want to show in pdf
     xml += "</body></pdf>";
     var file = nlapiXMLToPDF(xml);
     response.setContentType('PDF', 'Print.pdf ', 'inline');
     response.write(file.getValue()); 
}

thanks in advance

like image 896
Deepan Murugan Avatar asked Feb 07 '23 16:02

Deepan Murugan


1 Answers

The way I did it recently:

  • User Event Adds the Button that calls a suitelet (window.open('suitelet URL'))

  • Suitelet Renders the custom template

You can do the rendering like this insise a Suitelet (params: request, response), the custscript_pdf_template points to an html file on the cabinet using the NetSuite Advanced HTML syntax

    var template = nlapiGetContext().getSetting('SCRIPT', 'custscript_pdf_template');
    var purchaseOrder = nlapiLoadRecord('purchaseorder', tranId);
    var xmlTemplate = nlapiLoadFile(template);
    var renderer = nlapiCreateTemplateRenderer();
    var file;

    xmlTemplate = xmlTemplate.getValue();

    renderer.setTemplate(xmlTemplate);
    renderer.addRecord('record', purchaseOrder);

    xmlTemplate = renderer.renderToString();

    file = nlapiXMLToPDF(xmlTemplate);
    resObj = file.getValue();
    response.setContentType('PDF', 'printOut.pdf', 'inline');
    response.write(resObj)
like image 108
felipechang Avatar answered Feb 12 '23 00:02

felipechang