pdfnetsuitesuitescriptsuitescript2.0

How to access data from addRecord inside Adv PDF Template?


This is an Item Fulfillment record, but needing Sales Order data.

I've added the records. How would I access them in the Adv PDF Template?:

            renderer.addRecord('record', record.load({
                type: record.Type.ITEM_FULFILLMENT,
                id: 1025639
            }));
            renderer.addRecord('record', record.load({
                type: record.Type.SALES_ORDER,
                id: 1022380
            }));

Adv PDF Template. It shows the Item Fulfillment details perfectly, but I am not sure how I would get Sales Order line items to show. I need this so I can show Discount line items from the SO.

<#if record.item?has_content>
<p style="font-size: 12px; padding-bottom: 0;margin-bottom:0">
  These items will arrive soon!
  </p>
<table class="itemtable" style="width: 100%; margin-top: 10px;">
<thead>
    <tr>
    <th colspan="12">Item</th>
    <th align="right" colspan="3">Shipped</th>
    <th align="right" colspan="3">Price</th>
    <th align="right" colspan="3">Excise</th>
    <th align="right" colspan="3">Amount</th>
    </tr>
</thead>
<#list record.item?sort_by("displayname") as tranline><tr>
    <td colspan="12"><span class="itemname">${tranline.description}</span></td>
    <#setting number_format="0.##">
    <td align="right" colspan="3">${tranline.quantity}</td>
    <#setting number_format="currency">
    <td align="right" colspan="3">${tranline.custcol_nscs_itemsalesrate}</td>
    <td align="right" colspan="3">${tranline.custcol_excisecalculation}</td>
    <td align="right" colspan="3"><#assign lineitemtotal=(tranline.custcol_nscs_itemsalesrate * tranline.quantity) + (tranline.custcol_excisecalculation * tranline.quantity)>${lineitemtotal}</td>
    </tr>
    </#list></table>
</#if>

Solution

  • the first parameter is the name that the record will be referenced by in your template. So using the full syntax helps clarify:

        renderer.addRecord({
             templateName:'record', 
             record: record.load({
                 type: record.Type.ITEM_FULFILLMENT,
                 id: 1025639
              })
        });
        renderer.addRecord({
             templateName:'salesorder', 
             record: record.load({
                 type: record.Type.SALES_ORDER,
                 id: 1022380
              })
         }));
    

    and then

    <#list record.item as tranline></#list> <!-- item fulfillment lines -->
    ...
    <#list salesorder.item as soLine>...</#list> <!-- sales order lines -->