Simon G
Simon G

Reputation: 217

Scripting Issue with Netsuite Advanced PDF/HTML Template

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.

Upvotes: 0

Views: 5153

Answers (3)

michoel
michoel

Reputation: 3783

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>

Upvotes: 1

scheppsr77
scheppsr77

Reputation: 577

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.

Upvotes: 0

bknights
bknights

Reputation: 15367

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

Upvotes: 0

Related Questions