BWill
BWill

Reputation: 107

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.

Upvotes: 1

Views: 2828

Answers (3)

Shoaib Mehmood
Shoaib Mehmood

Reputation: 16

Above shared solution is fine 100% but when you save the layout in UI (Browser) it goes into infinite save loop, but it saves when you upload it via SDF.

Upvotes: 0

BWill
BWill

Reputation: 107

Here's the full code, in case it helps someone else out in the future. I'm running this as a purchase order advanced pdf and will eventually script a button that shows up on purchase order records and then creates a pdf from this advanced pdf via suitelet - in the meantime, the warehouse can print these by editing the purchase order and switching to the custom form that points to this advanced pdf template, then pressing print - not print labels.

Of note, when you try to save this code in Netsuite, it takes a while to validate and warns that there's an unexpected error (with no further details), I saved it anyway to test & it runs as I want it to.

Also of note, I'm using a lot of custom transaction line fields on my item record for details like container number, minimum quantity, etc. Feel free to change these field ids and any formatting to work for your organization.

<?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">
        </macro>
        <macro id="nlfooter">
            <table class="footer" style="width: 100%;"><tr>
            <td align="right"><span style="font-size:8pt; text-align:right;"><pagenumber/>&nbsp;/&nbsp;<totalpages/></span></td>
            </tr></table>
        </macro>
    </macrolist>
    <style type="text/css">
      table {
        <#if .locale == "zh_CN">
            font-family: stsong, sans-serif;
        <#elseif .locale == "zh_TW">
            font-family: msung, sans-serif;
        <#elseif .locale == "ja_JP">
            font-family: heiseimin, sans-serif;
        <#elseif .locale == "ko_KR">
            font-family: hygothic, sans-serif;
        <#elseif .locale == "ru_RU">
            font-family: verdana;
        <#else>
            font-family: sans-serif;
        </#if>
            font-size: 9pt;
            table-layout: fixed;
        }
       table {
            font-size: 12pt;
            margin-top: 10px;
            table-layout: fixed;
      	}
		td p { text-align:left }
</style>
</head>
<body header="nlheader" header-height="0" footer="nlfooter" footer-height="16pt" padding="0.125in 0.125in 0.125in 0.125in" width="152.4mm" height="101.6mm">

<#if record.item?has_content>
<#list record.item as item>
<#list 1..item.quantity as i>
<table class="itemtable" style="width: 100%; margin-top: 10px; height:96mm;">
    <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>
  </table><pbr/>
</#list>
</#list>
</#if>
</body>
</pdf>

Upvotes: 1

michoel
michoel

Reputation: 3783

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

Upvotes: 2

Related Questions