XML Objects and FreeMarker Expressions for Templates in NetSuite

NetSuite templates utilize XML objects for PDF generation, providing access to tax authority data with FreeMarker expressions.

·3 min read·11 views·View Oracle Docs

When generating a PDF, NetSuite provides specific XML objects that can be leveraged in FreeMarker expressions. These objects, containing the XML data exchanged with tax authorities during e-document certification, include:

  • authRequestXml: This object holds the complete XML request submitted to the tax authority.
  • authResultXml: This object contains the full XML response received from the tax authority.

Namespaces in XML

Managing namespaces in XML is essential for accurate data manipulation. If your XML incorporates namespaces, these should be declared at the top of the template using the following ns_prefixes directive:

freemarker
<#ftl ns_prefixes={
"soap": "http://schemas.xmlsoap.org/soap/envelope/",
"ns4": "http://nfse.abrasf.org.br"
}>

Always utilize the declared prefixes in your expressions as per the XML tag definitions. For instance, instead of using Envelope, write soap:Envelope.

Default Namespaces and XML Content Handling

In cases where XML features default namespaces (those without prefixes), the system automatically replaces them with prefixes like bta_default1, bta_default2, and so forth. These prefixes will remain consistent across environments, allowing you to rely on them while crafting and maintaining your templates.

To access XML elements, also include these new prefixes in your ns_prefixes directive and utilize them in your XPath expressions. Here's how an original XML snippet would look transformed with default namespaces:

Original XML Example:

xml
<EnviarLoteRpsEnvio xmlns="http://www.abrasf.org.br/nfse.xsd">

Transformed XML Example:

xml
<bta_default1:EnviarLoteRpsEnvio xmlns:bta_default1="http://www.abrasf.org.br/nfse.xsd">

Embedded XML in CDATA Sections

When handling response XMLs, be aware that they might feature CDATA sections containing embedded XML. If this embedded XML is present, the content retrieved through authRequestXml or authResultXml may not align with the original raw XML data. An example of this would be:

xml
1<Response>
2 <![CDATA[
3 <InnerXML>
4 <Value>Example</Value>
5 </InnerXML>
6 ]]>
7</Response>

To ensure you are accessing the precise XML meant for customization, modify the ECS MR Message Queue Service Map/Reduce script deployment and set the log level to Debug. During e-document certification, monitor the logs for entries corresponding to the ${alias} placeholder, which can either point to authRequestXml or authResultXml. These logs will display the XML content available to your PDF templates, appearing as follows:

xml
TaxAuthorityPdfGenerator - renderTaxAuthPDF: ${alias} data source before PDF render

XML Values Retrieval with FreeMarker

You can access specific values from the XML using FreeMarker expressions. Here are some practical examples:

Retrieve a Value from the Response XML This retrieves the 'RazaoSocial' (Company Name) element:

freemarker
${authResultXml["soap:Envelope"]["soap:Body"]["ns4:ConsultarLoteRpsResponse"]
["ConsultarLoteRpsResposta"]["ListaNfse"]["CompNfse"]["Nfse"]["InfNfse"]
["PrestadorServico"]["RazaoSocial"]}

Retrieve a Value from the Request XML This retrieves the 'Endereco' (Address) element:

freemarker
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["ListaRps"]["Rps"]
["InfDeclaracaoPrestacaoServico"]["Tomador"]["Endereco"]["Endereco"]}

Retrieve an Attribute from the Request XML This retrieves the 'versao' (version) attribute value:

freemarker
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["@versao"]}

Note: Use @ to access attribute values in the XML.

Key Takeaways

  • NetSuite's XML objects are critical for PDF generation related to tax authority communications.
  • Proper namespace management in XML is crucial for accurate data retrieval in FreeMarker.
  • To ensure compatibility, use defined prefixes in your expressions and recognize transformed default namespaces.
  • When dealing with embedded XML content, be aware of potential discrepancies with original data.
  • Debugging XML outputs can provide insights necessary for template customization adjustments.

Frequently Asked Questions (4)

Is the use of XML objects like authRequestXml and authResultXml mandatory for all PDF generations in NetSuite?
No, the use of XML objects such as authRequestXml and authResultXml is specifically related to generating PDFs for e-document certification with tax authorities. They are beneficial for businesses that need to meet compliance requirements.
Do the new XML objects require FreeMarker template customizations to function?
Yes, the new XML objects, authRequestXml and authResultXml, should be utilized within FreeMarker templates to customize PDF outputs according to the specific data exchanged with tax authorities.
What roles within a company are specifically impacted by the new XML objects in NetSuite 2026.1?
The roles particularly impacted are administrators, developers, tax compliance officers, and finance professionals, as they are involved in configuring templates, enhancing FreeMarker expressions, and ensuring accurate documentation for tax reporting.
If we partially implement these XML objects, will it affect existing PDF workflows in NetSuite?
The article doesn't specify the impact on existing workflows, but the new XML objects are meant to enhance PDF generation specifically for tax compliance, so any changes would primarily affect that area.

Weekly Update History (1)

Country-Specific Featuresupdated

Moved the PDF Templates Customization for Brazil help topic under PDF Templates Setup for Brazil.

View Oracle Docs
Source: XML Objects in the Template Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Accounting

View all Accounting articles →