ANS-0702 · PRINTING, PDF & EMAIL TEMPLATES
How to Display NetSuite Sales Order Shipping Address with Line Breaks in Advanced PDF/HTML Templates?
Learn to extract and correctly render multi-line shipping addresses from NetSuite sales orders, ensuring proper formatting in custom PDF documents.
Short answer
To display a NetSuite sales order's shipping address with line breaks in an Advanced PDF/HTML Template, retrieve the `shipaddress` field value. Then, replace newline characters (`n`) with HTML break tags (`<br/>`) using JavaScript. Finally, ensure the output is unescaped in your FreeMarker template using `?no_esc` to render the HTML tags correctly.
Scenario
Users generating custom Advanced PDF/HTML Templates for NetSuite sales orders often encounter issues when the shipping address, which contains multiple lines, does not display with proper line breaks. The default rendering might concatenate the address into a single line, making it difficult to read and unprofessional.
Solution
To correctly display the shipping address with line breaks in a NetSuite Advanced PDF/HTML Template, follow these steps:
Retrieve the Shipping Address:
When working with a loaded sales order record (e.g., in a SuiteScript context), retrieve the
shipaddressfield value. This field inherently contains the address formatted with line breaks.
javascriptvar address = record.getValue({ fieldId: 'shipaddress' });*Note: record refers to the loaded sales order record object in SuiteScript 2.x and later.*
Convert Newline Characters to HTML Break Tags:
To ensure line breaks are rendered as HTML in your PDF, replace the newline characters (
n) with HTMLtags.
javascriptaddress = address.replace(/n/g, '<br/>');Render in Advanced PDF/HTML Template:
When embedding the
addressvariable into your Advanced PDF/HTML Template (which uses FreeMarker), it is crucial to prevent auto-escaping of the HTMLtags. Use the?no_escbuilt-in to ensure the HTML is interpreted correctly.
html${address?no_esc}This will ensure that the tags are rendered as actual line breaks in the generated PDF.
Expert NetSuite Support
Need help with this NetSuite issue?
Printing, PDF & Email Templates consulting and configuration support
