1

In Netsuite, the #list loop for the item table will only render as many line items as there are number of of items. For example, if there's two items in a Sales Order, there will be only two line items in the PDF template as rendered by this example code:

<#if record.item?has_content>
<table class="itemtable" style="width: 100%;"><!-- start items -->
    <#list record.item as item>
    <#if item_index==0>
<thead>
    <tr>
        <th align="center" colspan="1">${item.quantity@label}</th>
        <th align="center" colspan="2">${item.item@label}</th>
        <th align="center" colspan="3">${item.description@label}</th>
        <th align="center" colspan="1">Unit Price</th>
        <th align="center" colspan="1">U/M</th>
        <th align="center" colspan="1">${item.amount@label}</th>
    </tr>
</thead>
</#if>
    <tr> <!--Move itemtable row up slightly to remove white space-->
        <td align="right" colspan="1">${item.quantity}</td>
        <td colspan="2"><span class="itemname">${item.item}</span></td>
        <td colspan="3">${item.description}</td>
        <td align="right" colspan="1">${item.rate?string.currency}</td>
        <td align="center" colspan="1">${item.units}</td>
        <td align="right" colspan="1">${item.amount?string.currency}</td>
    </tr>
</#list><!-- end items -->
</table>
</#if>

I have been following this official documentation for adding striping to line items in PDF templates https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N2866065.html

Whereupon you add this to of the items:

<tr style="background-color: ${((item_index % 2)==0)?string('#ffffff', '#ccffcc')};">

I need to extend the #list loop so a few "empty" rows with alternate striping are added to the bottom of the line item table:

Striping of line items with alternate background colors + extended

My use case has different number of line items for each order, otherwise I would just hard code three alternate colored rows myself. Thank you!

sweetarts
  • 11
  • 2

1 Answers1

0

You could just add some extra items to the list like <#list record.item + [{}, {}, {}] as item>. Then you need an #if that checks if item?has_content, and if not, then render a <tr> with one big spanning td, (unless in reality you need to handle null item.quantity, etc., in which case you don't need this extra #if).

As of using % for coloring, I don't know how many years the Netsuite FreeMarker is behind (except that a lot), but for a long time there's a feature like ${item?item_cycle('#ffffff', '#ccffcc', '#ffccff') in FreeMarker. If they don't yet have ?item_cycle, then I suggest writing a #function that returns the color code based on item_index (and that function will use index % 3 and #if-#elseif-#else, and #return inside).

Another possibility is just maintaining a counter yourself, so it can be independent of #list. Like <#assign rowCount = 0>, and then before each item you do <#assign rowCount++>. But I guess extending the list with empty items is nicer.

ddekany
  • 29,656
  • 4
  • 57
  • 64
  • Thank you @ddekany. I am still new so translating what you said into a code snippet is pretty hard for me. But I will try it out! This is a use case that comes up over and over again. – sweetarts Apr 27 '22 at 00:12