0

I need help with the Freemarker format for Netsuite (Advanced PDF/HTML Templates)

There are 3 important data values pulled for this records;

${item.quantity}     *Order Value*
${item.fulfilled}    *Fulfilled Value*
${item.backordered}  *Backorder Value*

Basically, what I try to accomplish is, to only show items that are "on backorder"

However this task seems to be a much harder than I have the time and skill for.

So, my plan B is using a separate template for the backorders (which is working well so far!)

The problem is that if I came across an item which is a NON-INVENTORY item, Netsuite does not calculate any qty for ${item.backordered}

SO

Is there any way I can "calculate" the backorder value with scripting in the template?
Can I use an arithmetic function (like below)?

item.quantity - item.fulfilled = item.backordered

Here is the basic format of the text surrounding this query;

        <#if record.item?has_content>
<table><#list record.item as item><#if item_index==0>
    <thead>
        <tr> 
        <th> QTY </th>
        </tr>
    </thead>
    </#if>
        <tr> 
        <td> ${item.backordered} </td>
        </tr>
</#list></table>
</#if>

I have a basic understanding of HTML and CSS, but scripting is still very new to me, so please only constructive criticism.

rocambille
  • 15,398
  • 12
  • 50
  • 68
Simon G
  • 217
  • 8
  • 24

3 Answers3

1

Try adding the following Freemarker helper function to your template:

<#function toNumber val>
    <#if val?has_content && val?length gt 0 >
        <#return val?html?replace('[^0-9.]','','r')?number >
    <#else>
        <#return 0 >
    </#if>
</#function>

This will ensure that all fields are correctly parsed as numbers, and you should be able to perform mathematical calculations on the fields without errors.

So you can replace:

<td> ${item.backordered} </td>

with:

<td> ${toNumber(item.quantity) - toNumber(item.fulfilled)} </td>
michoel
  • 3,725
  • 2
  • 16
  • 19
  • Exactly what I needed, thanks @michoel ! Works perfectly – Simon G Oct 14 '16 at 05:02
  • However I just noticed that when the item is exactly half fulfilled – Simon G Oct 14 '16 at 05:53
  • However, I just noticed that when the item is exactly half-fulfilled (i.e. ordered 10, fulfilled 5, 5 on backorder) that function returns the order qty (10) @michoel – Simon G Oct 14 '16 at 05:55
  • @SimonG That's weird. For troubleshooting, can you try outputting the following expressions to see what's going wrong: `${item.quantity}`, `${toNumber(item.quantity)}`, `${item.fulfilled}`, `${toNumber(item.fulfilled)}`? – michoel Oct 18 '16 at 23:31
0

See the answer to suitescript set custom column value netsuite for an example that uses arithmetic on line item values.

Community
  • 1
  • 1
bknights
  • 14,408
  • 2
  • 18
  • 31
  • Thanks @bknights I tried insert that example code into my template, just to see how it would work. However it keeps giving me errors, so I will have to spend some to re-structuring it so it will fit what I need. – Simon G Oct 12 '16 at 00:17
0

So I believe the root problem lays with the Java JAR NetSuite is using. It appears it has a null pointer bug with empty int/number type values.

I would recommend adding a UserEvent script to change the values to zero that are empty. This will prevent the error you are getting. You should be able to catch the PRINT type on the before load event. If the zero value is not carried over to the template, you can add a custom column field that is not stored and push the value there.

scheppsr77
  • 577
  • 2
  • 12