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.
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:
<#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:
<EnviarLoteRpsEnvio xmlns="http://www.abrasf.org.br/nfse.xsd">Transformed XML Example:
<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:
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:
TaxAuthorityPdfGenerator - renderTaxAuthPDF: ${alias} data source before PDF renderXML 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:
${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:
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["ListaRps"]["Rps"] ["InfDeclaracaoPrestacaoServico"]["Tomador"]["Endereco"]["Endereco"]}Retrieve an Attribute from the Request XML This retrieves the 'versao' (version) attribute value:
${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?
Do the new XML objects require FreeMarker template customizations to function?
What roles within a company are specifically impacted by the new XML objects in NetSuite 2026.1?
If we partially implement these XML objects, will it affect existing PDF workflows in NetSuite?
Weekly Update History (1)
Moved the PDF Templates Customization for Brazil help topic under PDF Templates Setup for Brazil.
View Oracle DocsWas this article helpful?
More in Accounting
- Intelligent Close Manager Portlet in NetSuite
The Intelligent Close Manager portlet offers a centralized view for managing tasks and exceptions in NetSuite, enhancing close processes.
- Applied Trans Date and Period Enhancements in NetSuite 20...
Latest updates in NetSuite 2024.1 enhance Accounting SuiteApps with transaction line distribution features.
- Journal Line Sublists Standardized for NetSuite 2026.1
With NetSuite 2026.1, journal line sublists are standardized to keyed configurations, allowing precise line updates and enhancing financial accuracy.
- Deployment Considerations for NFP SuiteApps in NetSuite
Understand the key deployment considerations for NFP SuiteApps to ensure successful installation and updates.
