Render a PDF template with data taken from different records

Suite script:

/**
         * Function defined to render the Picking ticket PDF
         * @param {String} ifId Item fulfillment internal id
         * @param {String} soId Sales order internal id
         * @param {String} subsidiary subsidiary internal id
         * @param {Array} tempDataSource datasource created by processing datas of item sublist 
         * @returns {fileObject}
         */
        function renderPdf(ifId, soId, subsidiary, tempDataSource) {
            try {
                //create the render object
                let renderTemp = render.create();
                //add the advance pdf template
                renderTemp.setTemplateByScriptId({
                    scriptId: "CUSTTMPL_JJ_PICKING_TICKET_IEGUN_105"
                });
                //add the item fulfillment record
                renderTemp.addRecord({
                    templateName: 'record',
                    record: record.load({
                        type: 'itemfulfillment',
                        id: ifId
                    })
                });
                //add the sales order record
                renderTemp.addRecord({
                    templateName: 'salesorder',
                    record: record.load({
                        type: 'salesorder',
                        id: soId
                    })
                });
                //add the subsidiary record
                renderTemp.addRecord({
                    templateName: 'subsidiary',
                    record: record.load({
                        type: 'subsidiary',
                        id: subsidiary
                    })
                });
                //add the data source as JSON object
                if (tempDataSource)
                    renderTemp.addCustomDataSource({
                        format: render.DataSource.JSON,
                        alias: "itemdata",
                        data: JSON.stringify({ items: tempDataSource })
                    });
                //render the PDF
                let pickTicketPdf = renderTemp.renderAsPdf();//generate the PDF file Object
                return pickTicketPdf;
            } catch (e) {
                log.error('error@render', e);
            }
        }

Adnace PDF Template:

<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
    <head>
        <link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}"
              src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}"
              src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
        <#if .locale == "zh_CN">
        <link name="NotoSansCJKsc" type="font" subtype="opentype"
              src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
        <#elseif .locale == "zh_TW">
        <link name="NotoSansCJKtc" type="font" subtype="opentype"
              src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
        <#elseif .locale == "ja_JP">
        <link name="NotoSansCJKjp" type="font" subtype="opentype"
              src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
        <#elseif .locale == "ko_KR">
        <link name="NotoSansCJKkr" type="font" subtype="opentype"
              src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
        <#elseif .locale == "th_TH">
        <link name="NotoSansThai" type="font" subtype="opentype"
              src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}"
              bytes="2" />
    </#if>
    <macrolist>
        <macro id="nlheader">
            <table class="header" style="width: 100%;">
					<tr>
						<td width="10%" style="">
						<#if subsidiary.logo@url?length != 0>
							<img src="${subsidiary.logo@url}" style="float: left; width: 35%; height:35%; "/>
							</#if>
						</td>
						<td align="left" width="35%" style="">
							<table style="width: 100%; ">
								<tr></tr>
								<tr>
									<td style="align:left; font-weight:bold; font-size:12px;">
										${subsidiary.legalname}</td>
								</tr>
								<tr>
									<td style="align:left; vertical-align: middle;">
									<#assign addr1 = subsidiary.mainaddress_text?keep_after('<br />')>
   									<#assign addr2 = addr1?keep_after('<br />')> 
									${addr1?keep_before('<br />')}, ${addr2?keep_before('<br />')}
									</td>
								</tr>
								<tr>
                                  <td style="align:left; vertical-align: middle;"><p style="text-align:left">Phone:${subsidiary.custrecord_ibs_sub_phone} Fax:${subsidiary.fax}</p></td>
								</tr>
							</table>

                         </td>
                         <td align="left" width="30%" style="">
							<table style="width: 100%; ">
							 <tr><td style="align:right; font-weight:bold; font-size:10px;"></td><td></td></tr>
                              <tr><td style="align:right; font-weight:bold; font-size:10px;"></td><td></td></tr>
                               <tr><td style="align:right; font-weight:bold; font-size:10px;"></td><td></td></tr>
                              <tr><td style="align:right; font-weight:bold; font-size:10px;"></td><td></td></tr>
                              <tr><td style="align:right; font-weight:bold; font-size:10px;"></td><td></td></tr>
							  <tr>
								<td style="align:right; font-weight:bold; font-size:10px;">Date:</td>
                                <td> <p style="text-align:left">${record.trandate}</p></td>
							  </tr>
                              <tr>
								<td style="align:right; font-weight:bold; font-size:10px;">Customer PO:</td>
                                <td> ${salesorder.otherrefnum}</td>
							  </tr>
                              <tr>
								<td style="align:right; font-weight:bold; font-size:10px;">Sales Order:</td>
                                <td><p style="text-align:left">
                                  ${salesorder.tranid}
                                  </p></td>
							  </tr>
                              <tr>
								<td style="align:right; font-weight:bold; font-size:10px;">Customer Account:</td>
                                <td> <p style="text-align:left">
                                  ${record.entity} </p></td>
							  </tr>
                              <tr>
								<td style="align:right; font-weight:bold; font-size:10px;">Page:</td>
                                <td><pagenumber/> of <totalpages/></td>
							  </tr>
							</table>
                         </td>
                         <td width="25%" style="font-size:17px; align: right; font-weight:bold; text-transform: uppercase;">PICKING TICKET</td>
					</tr>
				</table>
    <table height="20px;"><tr><td>&nbsp;</td></tr></table>
    <table style="width: 100%;">
        <tr><td colspan="16"><b>Bill To:</b></td><td colspan="1"></td><td colspan="16"><b>Ship To:</b></td></tr>
        <tr height="100px">
            <td colspan="16" style="border: 1px solid #b3b3b3; word-break: break-all;padding:10px"><p style="text-align: left;">${salesorder.billaddress}</p></td>
				<td colspan="1">
				</td>
              <td colspan="16" style="border: 1px solid #b3b3b3; word-break: break-all;padding:10px"><p style="text-align: left;">${record.shipaddress}</p></td>
        </tr>
    </table>
    <table height="20px;"><tr><td>&nbsp;</td></tr></table>
    <table width="100%" style="border: 0.5px solid #b3b3b3;">
        <tr style="height: 28px;">
            <th style="border: 0.5px solid #b3b3b3;">Sales Rep:</th>
            <th style="border: 0.5px solid #b3b3b3;">Ship Via:</th>
            <#if salesorder.custbody_ibs_ship_on_cus_accnt==true>
               <th width="23%" style="border: 0.5px solid #b3b3b3; padding-left: 4px;padding-right:4px;">Customer Freight Account:</th>
            </#if>
            <th style="border: 0.5px solid #b3b3b3;">Ship on Account:</th>
            <th style="border: 0.5px solid #b3b3b3;">Ship Type:</th>
            <th style="border: 0.5px solid #b3b3b3;">Priority Order:</th>
        </tr>
        <tr style="height: 28px;">
            <td class="quotetable"><p style="text-align: center;">${salesorder.salesrep}</p></td>
            <td class="quotetable"><p style="text-align: center;">${record.shipmethod}</p></td>
          <#if salesorder.custbody_ibs_ship_on_cus_accnt==true>
            <td class="quotetable"><p style="text-align: center;">${salesorder.custbody_ibs_cust_ship_accnt}</p></td>
          </#if>
          <td class="quotetable">${salesorder.custbody_ibs_ship_on_cus_accnt}</td>
          <td class="quotetable"><p style="text-align: center;">${salesorder.custbody_mhi_ibs_ship_type}</p></td>
          <td class="quotetable">${salesorder.custbody_mhi_ibs_is_priority_order}</td>
        </tr>
    </table>
</macro>

<macro id="childpagesfooter"><div>My Footer</div></macro>
<macro id="nlfooter">
<table>
    <tr><td width="22%" style="font-weight:bold; align:bottom;">IBS ELECTRONICS GROUP</td><td width="78%" style="border-bottom: 2px solid black;"></td></tr>
</table>
<table>
    <tr><td>
    </td></tr>

</table>
</macro>
<macro id="nlfooter">

<table width="100%">
              <tr><td width="30%"></td><td width="70%"></td></tr>
			<tr>
			<td width="30%" style="font-weight:bold; vertical-align:bottom; text-transform: uppercase;">${subsidiary.legalname}</td>
			<td width="70%" style=""><table width="100%" style="border-bottom: 2px solid black;"><tr><td width="100%"></td>
			</tr>
			</table>
			</td>
			</tr>
			</table>
			<table>
			<tr>
			<td> 
			<#assign addr1 = subsidiary.mainaddress_text?keep_after('<br />')> 
   									<#assign addr2 = addr1?keep_after('<br />')> 
									${addr1?keep_before('<br />')}, ${addr2?keep_before('<br />')} | Phone: ${subsidiary.custrecord_ibs_sub_phone} Fax: ${subsidiary.fax}
			</td>
			</tr>
			</table>
</macro>
        </macrolist>
<style type="text/css">* {
<#if .locale == "zh_CN">
font-family: NotoSans, NotoSansCJKsc, sans-serif;
<#elseif .locale == "zh_TW">
font-family: NotoSans, NotoSansCJKtc, sans-serif;
<#elseif .locale == "ja_JP">
font-family: NotoSans, NotoSansCJKjp, sans-serif;
<#elseif .locale == "ko_KR">
font-family: NotoSans, NotoSansCJKkr, sans-serif;
<#elseif .locale == "th_TH">
font-family: NotoSans, NotoSansThai, sans-serif;
<#else>
font-family: NotoSans, sans-serif;
</#if>
        }
        table {
        table-layout: fixed;
        }
        td{
        font-size: 11px;
        }

        th{
        font-size: 11px;
        font-weight:bold;
        align: center;
        vertical-align: middle;
        }

        td.headertable{
        font-weight:bold;
        align: right;

        }
        td.adressText{
	    padding: 10px;
        line-height: 20pt
        }
        td.quotetable{
        vertical-align: middle;
        border: 0.5px solid #B3B3B3;
        align: center;
        }
        td.footertable{
        font-size: 9px;
        padding-left: 10px;
        padding-right: 10px;
        }

        td.footertableheading{
        font-size: 9px;
        font-weight:bold;
        padding-left: 10px;
        padding-right: 10px;
        }

        td.footertotaltable{
        font-size: 10px;
        font-weight:bold;
        align: right;
        }
        td.footertablehead{
        font-size: 10px;
        font-weight:bold;
        padding-right: 10px;
        }


        </style>
        </head>

<body header="nlheader" header-height="40%" footer="nlfooter" footer-height="20pt"
      padding="0.33in 0.33in 0.33in 0.33in" size="Letter">

<#if itemdata?has_content && itemdata.items?has_content>
<table style="padding-top:1px;width: 100%; border:0.5px solid #b3b3b3;"><#list itemdata.items as item><#if item_index==0>

    <thead>
        <tr style="height: 35px;">
            <th  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-left: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>Line</b></th>
          <th  align="center" colspan = "12" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>MPN/MFR/Description/LOT/COO/Date Code</b></th>
            <th  align="center" colspan = "2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>Ship Date</b></th>
            <th  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>Base QTY</b></th>
            <th  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>Sale QTY</b></th>
            <th  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;"><b>On Hand <br/>Bin</b></th>
        </tr>
    </thead>
</#if>
  <tr>
    <td  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">${item.custpage_jj_item_line}</td>
    <td  align="left" colspan="12" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">
    <#if item.custpage_jj_mpn?has_content ||  item.custpage_jj_mfr?has_content || item.custpage_jj_description?has_content>
						<p style="line-height:12pt; padding-top: -1 px; padding-bottom: -1 px;">
							<#if item.custpage_jj_mpn?has_content>
								<b>MPN: </b>${item.custpage_jj_mpn}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</#if>
							<#if item.custpage_jj_mfr?has_content>
								<b>MFR: </b>${item.custpage_jj_mfr}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</#if>
							<#if item.custpage_jj_description?has_content><b>DESC: </b>${item.custpage_jj_description}</#if>
						</p>
					</#if>
      <#if item.custpage_jj_lot?has_content || item.custpage_jj_coo?has_content ||  item.custpage_jj_datecode?has_content>
						<p style="line-height:12pt; padding-top: -1 px; padding-bottom: -1 px;">
                          <#if item.custpage_jj_lot?has_content>
								<b>LOT: </b>${item.custpage_jj_lot}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</#if>
							<#if item.custpage_jj_coo?has_content>
								<b>COO: </b>${item.custpage_jj_coo}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</#if>
							<#if item.custpage_jj_datecode?has_content>
								<b>Date Code: </b>${item.custpage_jj_datecode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</#if>
						</p>
					</#if>
    </td>
    <td  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">${item.custpage_jj_ship_date}</td>
    <td  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">${item.custpage_jj_orderd_qty}</td>
    <td  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">${item.custpage_jj_qty_shipped}</td>
    <td  align="center" colspan="2" style="border-right: 0.5px solid #B3B3B3;border-bottom: 0.5px solid #B3B3B3;">${item.custpage_jj_onhand}</td>
</tr>
</#list></table>
   <table width="100%" style="padding-top: 10px; page-break-inside: avoid;">
     <tr><td class="footertablehead"><b>Shipping Requirements:</b></td></tr>
     <tr height="50px"><td>${record.custbody_mhi_ibs_ship_requirements}</td></tr>
     <tr><td class="footertablehead"><b>Additional Shipping Requirements:</b></td></tr>
     <tr height="50px"><td>${record.custbody_ibs_additional_ship_req}</td></tr>
  </table>
        </#if><br />&nbsp;
        </body>
        </pdf>

Leave a comment

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