ANS-1834 · PRINTING, PDF & EMAIL TEMPLATES

How to Resolve ‘Error Reading Included File’ in NetSuite FreeMarker Templates

Learn how field type selection impacts #include tag functionality for dynamic file paths in NetSuite email templates.

Short answer

To resolve "Error reading included file" when using the #include tag in NetSuite FreeMarker email templates, change the field type storing the file path from 'free-form text' to 'hyperlink'. Free-form text fields are subject to HTML escaping, which can corrupt paths, whereas hyperlink fields are generally better suited for dynamic URL or file path insertion.

Scenario

Users attempting to dynamically include files into NetSuite FreeMarker email templates using the #include tag may encounter an "Error reading included file." This typically occurs when the file path is stored in a custom field and the FreeMarker engine fails to correctly interpret the path, preventing the template from rendering as expected.

Solution

When encountering issues with the #include tag in FreeMarker email templates, particularly an "Error reading included file," the field type used for storing the file path can be a critical factor. NetSuite's FreeMarker engine appears to handle different field types with varying behaviors, especially concerning string escaping.Free-form text fields are subject to HTML escaping when rendered in FreeMarker templates, particularly when their content is used within quotation marks. This escaping can inadvertently alter file paths, leading to errors when the #include directive attempts to resolve the path.In contrast, switching the path's field type from free-form text to hyperlink can resolve this issue. While hyperlink fields are designed for URLs and often require less explicit escaping for direct URL insertion, it is important to note that robust rendering may still necessitate specific FreeMarker formatting (e.g., concatenation or the ?no_esc built-in) to ensure the URL is correctly processed without unwanted characters. The direct interaction of the #include tag with these field types for file paths may vary depending on field configuration and NetSuite version.Therefore, when a soft-coded string representing a file path is required within a FreeMarker email template, especially for use with the #include tag, it is recommended to use a hyperlink field type rather than a standard free-form text field to mitigate potential escaping issues.

Expert NetSuite Support

Need help with this NetSuite issue?

Printing, PDF & Email Templates consulting and configuration support

Talk to a consultant