Currently, I have a table of values/attributes in my Custom Transaction Form.
I want to write an Advanced PDF Template, so when I print the form as PDF, some values are grouped to different sections.
For example, my form has four attributes, called Store, Product ID, Prices, and NumOfSales, like the following.
I am wondering if Advanced PDF Template - Freemaker has group_by() and sum() functions OR if I need to use SuiteScript to achieve that. If I need to used SuiteScript, how to combine Advanced PDF Template and Script together. Thanks for your help.
If you can do the processing/grouping prior to passing data to freemarker you are better off. However if you are doing something like extending the standard transaction forms that isn't a simple option.
You can simulate grouping by using sequence operations. (see http://freemarker.org/docs/ref_builtins_sequence.html)
Then:
<#assign seen_style = []>
<#list record.item?sort_by('custcol_style') as lineitem>
<#assign lineStyle = lineitem.custcol_style>
<#if seen_style?seq_contains(lineStyle)>
<#else>
<#assign seen_style = seen_style + [lineStyle]>
<#assign styleTotal = 0>
<#list record.item?sort_by('custcol_size') as styleItem>
<#if lineStyle == styleItem.custcol_style>
<#assign styleTotal = styleTotal + styleItem.quantity>
</if>
</#list>
<div>${lineStyle} has ${styleTotal}</div>
</#if>
</#list>