Search code examples
netsuitefreemarkersuitescript2.0

Freemarker & SuiteScript rendered Advanced PDF - Replace double hyphens within a field


I have a scenario where I have an XML advanced PDF template, and SuiteScript renders the PDF.

However, one of the fields on the record I'm working with, is a text area, and the user has entered -- (to hyphens) in the text.

The PDF when rendering doesn't like this, as -- renders as escape characters when the fields are embedded with BFO.

what I want to do, is dynamically replace this field

${item.customtextfield?replace("--","..","r") or something like that, and see if that gets around the issue.

A bit like replacing & with & in URLs for images.

My regex knowledge is not very good within freemarker, so not sure if above is correct.


Solution

  • I haven't seen the rest of your code, but if your field is a custom body field, you probably need to access record instead of item.

    This worked for me (in my case, custbody_textarea is a custom field on invoice record):

    <#if record.custbody_textarea?has_content>
      ${record.custbody_textarea?replace("--", "..")}
    </#if>