How To Fix Oblique Advanced PDF/HTML Template Errors In Netsuite

When working with Advanced Templates, and the FreeMarker syntax in NetSuite there can be some oblique errors which make it difficult to diagnose.

To help diagnose any such errors, I highly recommend writing your templates in a code editor.

I personally prefer the editors from JetBrains as they package everything you need in one nice editor. To effectively write FreeMarker templates with syntax highlighting and auto-completion you will need the IntelliJ Editor.

Template cannot be saved error

When you get an error from NetSuite such as something of the form:

The template cannot be saved due to the following errors: Parse exception during template merging. Cause: Encountered “&” at line 128, column 89 in template. Was expecting one of: … … “false” … “true” … … … “.” … “+” … “-” … “!” … “[” … “(” … “)” … “{” … …

– NetSuite Advanced Template error

What I’ve found is when I return to my editor to hunt for the problem I don’t see anything on line 128??

So what is going on with this error?

To properly diagnose the error, copy the code as it is in the Advanced Template window. Then paste this code back into your text editor and then look at line 128.

You should notice with the newly pasted code that NetSuite may have parsed through some lines and edited it for you. Some lines may have been concatenated together and other lines may have page breaks.

With the newly inserted code you should be able to better diagnose the problem.

In the case of the error above I would navigate to line 128, and I’d see where NetSuite is struggling with my template code.

In the example above it appeared NetSuite doesn’t like using the   HTML entity directly in the code. So just changed this to a space character.

The error appeared to go away when I tried saving the template again. In fact if you apply any innocuous edit it should save just fine.

The important thing to remember though, especially if you’re scratching your head and looking at the error, and your code on side-by-side screens: copy the code from NetSuite and then you’ll see the error.