FreeMarker Formatting Method

NetSuite formatting is lost when you customize NetSuite standard fields. If you print hard-coded values which came from a custom data source or were calculated from standard fields, the format won't match the format of standard record fields. When editing the template source code, the nsformat_*() formatting method makes it possible to format FreeMarker custom variables in the same way NetSuite formats standard fields. It also decreases the need for hardcoding. The nsformat_*() method formats the specific string, number, date, or amount results in the same format used on a standard NetSuite field. With this formatting method, it's possible to apply localization to custom variables, ensuring consistent output.

The following table shows some examples of standard fields in use:

Example

Output

${record.custbody_show_int}

1,234

${record.custbody_show_int+1}

1235

${nsformat_number(record.custbody_show_int+1)}

1,235

${record.custbody_show_date_time}

Dec 18, 2019 5:05:00 AM

The following table shows some examples of the ${nsformat_*()} formatting method in use:

Method

Example

Output

${nsformat_date(date|string)}

${nsformat_date("2018-12-04T10:40:00.000")}

12/4/2018

${nsformat_datetime(date|string)}

${nsformat_datetime("2018-12-04T10:40:00.000Z")}

${nsformat_datetime("2018-12-04T10:40:00.000")}

${nsformat_datetime(itemDateTime)}

Dec 4, 2018 2:40:00 AM

Dec 4, 2018 10:40:00 AM

Dec 4, 2018 10:40:00 AM

${nsformat_time(date|string)}

${nsformat_time("2018-12-04T10:40:00.000")}

10:40:00 AM

${nsformat_currency(number|string)} or with optional second string ${nsformat_currency(number|string, string)}

${nsformat_currency(10.20, "EUR")}

€10,20

${nsformat_rate(boolean|string|number)} or with optional second string ${nsformat_rate(number|string, string)}

${nsformat_rate(32, "USD")}

$32.00

${nsformat_number(number|string)} or with optional second locale string ${nsformat_number(number|string, string)}

${nsformat_number("9999999.99)}

${nsformat_number (999999999.99, "cs_CZ”)}

999,999,999.99

999 999 999,99

${nsformat_boolean(boolean|string|number)}

${nsformat_boolean("true")}

Yes

${nsformat_password(string)}

${nsformat_password("p4sw0rd")}

*****

${nsformat_percent(number|string)}

${nsformat_percent("100")}

100%

${nsformat_email(string)}

${nsformat_email(“[email protected]”)}

clickable email address

${nsformat_url(string)}

${nsformat_url(“http://example.com”)}

clickable link

Formatters accept numbers in double precision floating point representation.

If the input is an empty string or null value, then the output is also represented as an empty string.

Related Topics

General Notices