-2

I'm trying to do the following in Freemarker via NetSuite:

I have the following data on a transaction record i.e. imagine a payment record with a number of lines

Doc No.   Amount
1         100
1         100
2         50
3         200
4         50
4         25
5         1000

and I want to be able to output:

Doc No.       Total
1             200
2             50
3             200
4             75
5             1000

I think you need to use #list and #assign but not sure??

NS101
  • 9
  • 3
  • If the framework indeed tries to push calculations like this on the template, that's a problem. While it's possible to do in FreeMarker (because it's complete enough for that as a language), it will be very ugly and slow. It's not SQL. Can't NetSuite instead give the summary to the template? If not, can't you expose some Java utility to the template that does this? – ddekany Oct 03 '19 at 05:52

1 Answers1

1

Here is a snippet that should help out with this question (I hope). This is pulled from one of my PDF templates, where I'm adding up the locationTotal variable.

<#list record.item as item>
  <#assign currentLocation=item.custcol_location>
    <#if currentLocation=="">
      <#assign currentLocation=record.entity>
    </#if>
    <#if item.itemtype!="Discount" && locationsProcessed?seq_index_of(currentLocation)==-1>
      <#assign locationTotal=0>
      <#list record.item as item2>
        <#assign compareLocation=item2.custcol_location>
        <#if compareLocation=="">
          <#assign compareLocation=record.entity>
        </#if>
        <#if compareLocation==currentLocation>
          <#assign locationTotal=locationTotal+item2.amount>
        </#if>
      </#list>
    <#assign newList=newList+[{"location":currentLocation,"total":locationTotal}] >
    <#assign locationsProcessed=locationsProcessed+[currentLocation] >
  </#if>
</#list>
w3bguy
  • 2,215
  • 1
  • 19
  • 34
  • Hi @W3BGUY, Thanks for this! I can make this out however, I get an error as i don't think the first locationsProcessed (i.e. in locationsProcessed?seq_index_of) is declared before being used? I maybe probably wrong though! – NS101 Oct 02 '19 at 13:46
  • Yeah, this is just an example of how to use the list and assign. This particular freemarker script is about two thousand lines. :) – w3bguy Oct 02 '19 at 15:11
  • 1
    Thanks W3BGUY, it is helping me a long way! – NS101 Oct 02 '19 at 15:40
  • 1
    @w3bguy https://stackoverflow.com/questions/76251321/sum-of-invoice-amount-based-on-currencies-in-netsuite-pdf-template tried the same but didnt work for me – Addy May 16 '23 at 13:06
  • @Addy, guessing they probably changed this since 2019. I have not had a need to deal with this in a long time... ;) – w3bguy May 17 '23 at 15:04