ANS-1936 · PRINTING, PDF & EMAIL TEMPLATES
How to Sort a Table in NetSuite Advanced PDF/HTML Templates by a Column?
Leverage the FreeMarker sort_by function within NetSuite Advanced PDF/HTML templates to arrange data lists based on specific column values.
Short answer
To sort a table in a NetSuite Advanced PDF/HTML template, use the FreeMarker sort_by function. Apply it to your list variable, specifying the column name for sorting. For ascending order, the function sorts directly; for descending order, chain the reverse function after sort_by.
Scenario
NetSuite users often need to present data in Advanced PDF/HTML templates in a specific order. When displaying lists or tables, the default order may not meet reporting requirements. The challenge is to dynamically sort these lists based on the values of a particular column within the template itself.
Solution
To sort a list or table in an Advanced PDF/HTML template, utilize the FreeMarker sort_by function. Consider a list variable, myList, which contains a column named 'myCol'. The following FreeMarker expression can be used to obtain a sorted list:
${myList?sort_by('myCol')}This expression will produce a new list, sorted by the 'myCol' column in ascending order. To achieve descending order, apply the reverse function to the sorted list:
${myList?sort_by('myCol')?reverse}Expert NetSuite Support
Need help with this NetSuite issue?
Printing, PDF & Email Templates consulting and configuration support
