Search code examples
pdf-generationnetsuitefreemarkerbfo

How do I loop or repeat line items by their quantity count in Netsuite Advanced PDFs?


The brief version: In Netsuite Advanced PDFs using BFO & Freemarker, how do I repeat a line item x times where x is the item quantity?

The code:

<#if record.item?has_content>
<table class="itemtable" style="width: 100%; margin-top: 10px; 
height:96mm;"><!-- start items --><#list record.item as item>
<tr>
  <td>
    <table style="width: 100%; height:100%;">
        <tr>
        <td width="70%"><#if item.custcol_upccode?length != 0><barcode bar-width="2" codetype="UPCA" showtext="true" height="50" value="${item.custcol_upccode}"/></#if></td>
        <td width="30%" align="right" valign="bottom"><span style="font-weight:bold; vertical-align:bottom;">${item.custcol_item_collection}</span></td>
        </tr>
        <tr height="10">
        <td colspan="2"></td>
        </tr>
        <tr>
        <td><p style="font-size:14pt; line-height:140%; padding:0 12pt 0 12pt;">${item.custcol_displayname}</p></td>
          <td align="right" valign="middle"><span style="font-size:16pt; line-height:140%; font-weight:bold;"><#if record.custbody_container_id?has_content>${record.custbody_container_id}<#else>${record.tranid}</#if></span></td>
        </tr>
        <tr>
        <td align="center" style="text-align:center !important;"><#if item.custcol_moq!=0 && item.custcol_moq!=1><div style="text-align:center !important; width:100%; height:100%; background-color:#000; padding:0 12pt 0 12pt;"><span style="color:#FFF; text-align:center !important; font-weight:bold;">${item.custcol_moq} PER BOX</span></div></#if></td>
          <td align="right"><span style="font-size:14pt; line-height:140%; font-weight:bold;">
            <#setting date_format="yyMM">
            <#setting locale="en_US">
            ${record.custbody_etd}
            </span></td>
        </tr>
        <tr>
        <td colspan="2"><#if item.item?length != 0><barcode bar-width="1" codetype="code128" showtext="false"  height="70" value="${item.item}"/></#if></td>
        </tr>
        <tr>
          <td colspan="2"><span style="font-size:20pt; line-height:140%; font-weight:bold; padding:0 12pt 0 12pt;">${item.item}</span></td>
        </tr>
    </table>
  </td>
</tr>
</#list><!-- end items -->
</table>
</#if>

The long version: What I'm trying to accomplish is this - I'm making item labels for receiving purchase orders. The label record in Netsuite is extremely limited and won't let me pull in additional item record details beyond these Label record options

So my work around is to create a separate purchase order transaction form that points to a new purchase order advanced pdf containing the code above and restricting it to a body of 6" x 4" for thermal label printing. Each line item becomes a separate table and a new label.

A purchase order that contains these 3 items

enter image description here

Creates these labels

Item Labels from Netsuite Purchase Order

The Questions:

  1. Why is it only returning 2 of the 3 items?
  2. And how do I split each line item to repeat x number of times where x is the item.quantity?

In this example, the first label should repeat 75 times, the second label should repeat 65 times, and the third label should show up and repeat 60 times. The end goal is to be able to press print on the pdf and have it produce a label for each item received.


Solution

  • To accomplish this, you need a second "<list>" loop that repeats as many times as the quantity of the line:

    <#list record.item as item>
      <#list 1..item.quantity as i>
         <!-- your label here -->
      </#list>
    </#list>
    

    I am not sure why you you are not getting the third item in your attempt.

    I would also suggest instead of wrapping your entire pdf inside a table, you can just have a table for each label, and use the <pbr/> tag to force a break between pages