Freemarker Nested If Statements
We have been using pick, pack, ship since we have a drop ship warehouse. Our original Sales Rep for Netsuite, or this was a default setting, had our picking tickets to show the item.quantitycommitted field. Since I was the only one using the pick, pack, ship properly per Netsuites instructions, some items were being sent to stock versus getting pulled for orders as some of you may know, not marking items picked, will not reset picking ticket status for when more items get received. Long story short I have been working on resolving this issue but introducing the proper way to pick pack ship, however the picking ticket was not reflecting the proper amounts that needed pulled. I got it working, with errors on saving, completely except for if there have been items billed. That is where I am stuck. The following code is what I am trying to use and I get 0 errors while saving or when I preview, however it does not seem to work when I try to generate a picking ticket. I get this error;
“Error
An unexpected error has occurred. Please click here to notify support and provide your contact information.”
Hi,
There are a few things I would take a look at here:
Firstly, if you’re going to be performing arithmetic, it’s probably best to use ?number to make sure everything is a number.
Then you can use == 0 instead of == “0”.
You had an = instead of a == somewhere.
And the whole thing looks a lot simpler if you use elseif.
Let me know if you need any further help.
Thanks,
Chris
<#assign billed=item.quantitybilled?number>
<#assign picked=item.quantitypickpackship?number>
<#assign committed=item.quantitycommitted?number>
<#assign qty=item.quantity?number>
<td colspan=”3″><span class=”itemname”>${item.item}</span><br />${item.description}</td>
<td style=”width: 125px;”>${item.options}</td>
<td style=”width: 86px;”>${item.quantity}</td>
<td>${item.quantitypickpackship}</td>
<td style=”width: 47px; text-align: center;”>${item.units}</td>
<td>
<#if billed == 0 >
<#if picked == 0 >
${committed}
<#elseif billed == picked >
${committed}
<#else>
${(committed-picked)}
</#if>
<#elseif billed == picked >
${committed}
<#else>
${(qty-picked)}
</#if>
</td>
</tr>
I believe I had tried this, however since I am out of ideas I tried it anyways. Here is the warning produced on saving.
Error on line 119, column 9 in template. Detail...Can't convert this string to number: "" The blamed expression: ==> item.quantitybilled?number [in template "template" at line 119, column 25] ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign billed = item.quantitybilled?... [in template "template" at line 119, column 9] ---- Error on line 120, column 9 in template. Detail...
Can't convert this string to number: "" The blamed expression: ==> item.quantitypickpackship?number [in template "template" at line 120, column 25] ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign picked = item.quantitypickpac... [in template "template" at line 120, column 9] ---- Error on line 121, column 9 in template. Detail...
Can't convert this string to number: "" The blamed expression: ==> item.quantitycommitted?number [in template "template" at line 121, column 28] ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign committed = item.quantitycomm... [in template "template" at line 121, column 9] ---- Error on line 122, column 9 in template. Detail...
Can't convert this string to number: "9,999.99" The blamed expression: ==> item.quantity?number [in template "template" at line 122, column 22] ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign qty = item.quantity?number [in template "template" at line 122, column 9] ---- Error on line 129, column 9 in template. Detail...
The following has evaluated to null or missing: ==> billed [in template "template" at line 129, column 14] ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #if billed == 0 [in template "template" at line 129, column 9] ----
I went ahead and saved anyways, but I still got the same Error page when generating a picking ticket.
Here is the piece of code that is currently in place and functioning, except it does not take into account anything that has been billed.
<tr><#assign committed=item.quantitycommitted><#assign picked=item.quantitypickpackship><#assign qty=item.quantity><#assign qtytopick=committed-picked><#assign qtytopicklt0=qty-picked><td colspan="3"><span class="itemname">${item.item}</span><br />${item.description}</td><td style="width: 125px;">${item.options}</td><td style="width: 86px;">${item.quantity}</td><td>${picked}</td><td style="width: 47px; text-align: center;">${item.units}</td><td><#if qtytopick lte 0 && committed != 0 > ${qtytopicklt0} <#else> ${qtytopick} </#if></td></tr>
That’s so annoying that it gives empty strings instead of zeros.
Here’s a slightly revised version:
<tr>
<#assign billed=0>
<#if item.quantitybilled?has_content>
<#assign billed=item.quantitybilled?number>
</#if>
<#assign picked=0>
<#if item.quantitypickpackship?has_content>
<#assign picked=item.quantitypickpackship?number>
</#if>
<#assign committed=0>
<#if item.quantitycommitted?has_content>
<#assign committed=item.quantitycommitted?number>
</#if>
<#assign qty=item.quantity?number>
<td colspan=”3″><span class=”itemname”>${item.item}</span><br />${item.description}</td>
<td style=”width: 125px;”>${item.options}</td>
<td style=”width: 86px;”>${item.quantity}</td>
<td>${item.quantitypickpackship}</td>
<td style=”width: 47px; text-align: center;”>${item.units}</td>
<td>
<#if billed == 0 >
<#if picked == 0 >
${committed}
<#elseif billed == picked >
${committed}
<#else>
${(committed-picked)}
</#if>
<#elseif billed == picked >
${committed}
<#else>
${(qty-picked)}
</#if>
</td>
</tr>
I tried this and on saving the only error was
Error on line 131, column 9 in template. Detail... Can't convert this string to number: "9,999.99" The blamed expression: ==> item.quantity?number [in template "template" at line 131, column 22]---- FTL stack trace ("~" means nesting-related): - Failed at: #assign qty = item.quantity?number [in template "template" at line 131, column 9] ----
I saved and tested this anyways, however I still get the same basic error page Netsuite has.
(PS: Not sure what the <p class> getting added in by this forum is for.)
What frustrates me more, is when I test this in the Online Template Tester, it works exactly as it should.
Updates! I got it almost working.
Hi,
Really pleased you’re making progress and I’ve just spotted an error which I really should have noted earlier…
When comparing values, we should be using “==“ which may well explain the behaviour you are describing.
Chris
Thank you, it has definitely been a process thusfar.
I have tried with “=” as well as with “==” and there is zero effect. Matter of fact, within the Netsuite code editor, it changes the colors of the arithmetic and the 2nd “=”.
1 “=”
2 “==”
Here is the code working exactly as it should. I even tried using “0” instead of just 0 with the If statements and it errors due to attempting to compare a number to a string.
I do not understand why it will not work in Netsuite.
Further testing verified that the template is not pulled the quantity that has been billed. I removed the entire if elseif else statements and put just the 4 variables with labels in to see what each line is pulling and everything is correct, except billed is staying 0. I even went into the console and loaded the sales order and checked each line and verified that it is item.quantitybilled.