ANS-1424 · PRINTING, PDF & EMAIL TEMPLATES
How to Remove Quantity Tags from NetSuite Advanced PDF Inventory Detail
Learn how to use FreeMarker's replace function with regular expressions to clean up inventory detail fields on NetSuite packing slips.
Short answer
To remove quantity tags like (99) from multiline inventory detail fields in NetSuite Advanced PDF templates, use the FreeMarker replace function with a regular expression. The correct syntax, accounting for FreeMarker's specific regex handling of backslashes and newlines, is ${tranline.inventorydetail?replace("\(\d*\)"," ","r")}. This expression targets and removes numeric quantities enclosed in parentheses.
Scenario
NetSuite Advanced PDF templates often utilize inventory detail from Item Fulfillments to generate printable packing slips. A common requirement is to display bin numbers without associated quantities, which may appear in parentheses (e.g., AB1234(99)). The challenge is to remove these quantity tags from the multiline inventory detail field directly within the PDF template without resorting to scripting, aiming for a clean output like AB1234.
Solution
Yes, FreeMarker supports using regular expressions within its replace function. The standard use of the replace function, which only works with exact string matches, is demonstrated below:
${tranline.inventorydetail?replace("car", "bulldozer")}This would result in: "this is a bulldozer abulldozerus"
By adding the 'r' flag as an optional third parameter, the FreeMarker compiler is instructed to treat the search string as a regular expression. For removing parentheses and the characters between them, an initial regex attempt might be:
${tranline.inventorydetail?replace("(.*)"," ","r")}However, this standard regex code crashes the FreeMarker compiler due to how it interprets backslashes. The backslash character needs to be doubled:
${tranline.inventorydetail?replace("\(.*\)"," ","r")}A further consideration is that the .* sequence, by default, should not pick up newline characters, but in FreeMarker, it does. To specifically target digits within the parentheses and avoid unintended matches across lines, .* should be replaced with \d*. The final, working solution is as follows:
${tranline.inventorydetail?replace("\(\d*\)"," ","r")}Expert NetSuite Support
Need help with this NetSuite issue?
Printing, PDF & Email Templates consulting and configuration support
