Function to Render Template File

    function renderTemplateFile(itemLineDetails,ffID,recordDetails) {
        try{
        var templateRenderer = render.create();

        templateRenderer.setTemplateById(internal id of pdf template);

        templateRenderer.addRecord('record', record.load({
            type: record.Type.ITEM_FULFILLMENT,
            id: ffID
        }));
        templateRenderer.addCustomDataSource({
            format: render.DataSource.OBJECT,
            alias: "itemLineDetails",
            data: {
                itemLineDetails: itemLineDetails
            }
        });
          templateRenderer.addCustomDataSource({
                format: render.DataSource.OBJECT,
                alias: 'recordDetails',
                data: recordDetails
            });
        var pdf = templateRenderer.renderAsPdf();
        pdf.name = "Commercial Invoice " + ffID + ".pdf";
        return pdf;
        // log.debug("end", scriptInstance.getRemainingUsage());
    } catch(e){
            log.debug("error",e)
        }

    }

Leave a comment

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