XML Objects for PDF Generation in NetSuite Accounting
Discover how to use XML objects in FreeMarker for PDF generation in NetSuite. Streamline e-document certification processes.
TL;DR
NetSuite provides XML objects that enhance PDF generation capabilities when interacting with tax authorities. These objects facilitate the e-document certification process, allowing for effective XML data handling within FreeMarker templates.
What XML Objects Are Available?
When generating PDFs, NetSuite supplies two key XML objects for integration with FreeMarker expressions:
authRequestXml: Contains the full XML request sent to the tax authority.authResultXml: Contains the full XML response received from the tax authority.
These objects are critical for ensuring accurate information exchange during the e-document certification.
How to Use Namespaces in XML
If the XML you are working with includes namespaces, you should declare them at the top of your FreeMarker template using the ns_prefixes directive. Here’s an example:
<#ftl ns_prefixes={ "soap": "http://schemas.xmlsoap.org/soap/envelope/", "ns4": "http://nfse.abrasf.org.br"}>This directive allows you to refer to the XML elements correctly using the necessary prefixes. For instance, use soap:Envelope instead of just Envelope.
Handling Default Namespaces and XML Content
Default Namespaces Replacement
NetSuite automatically replaces default namespaces (those without prefixes) in the XML with prefixes like bta_default1, bta_default2, and so on. This replacement is consistent across different environments, making it easier to maintain templates.
You can include these prefixes in your ns_prefixes directive and use them in XPath expressions. Here’s a comparison of the original XML and the transformed version:
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
Sometimes, the XML response may contain CDATA sections, which may include additional XML content. If the XML retrieved through authRequestXml or authResultXml does not match the original raw XML source, it may be due to embedded XML in these CDATA sections.
Example of Embedded XML:
1<Response>2 <![CDATA[3 <InnerXML>4 <Value>Example</Value>5 </InnerXML>6 ]]>7</Response>To confirm the XML available for customization, you should adjust the log level to Debug within the ECS MR Message Queue Service Map/Reduce script deployment. Check logs for entries containing ${alias}, which can be either authRequestXml or authResultXml.
Retrieving XML Values with FreeMarker
Here are a few examples to guide you in retrieving values from the XML:
Value from the Response XML
To retrieve the 'RazaoSocial' (Company Name) from the XML response:
${authResultXml["soap:Envelope"]["soap:Body"]["ns4:ConsultarLoteRpsResponse"] ["ConsultarLoteRpsResposta"]["ListaNfse"]["CompNfse"]["Nfse"]["InfNfse"] ["PrestadorServico"]["RazaoSocial"]}Value from the Request XML
To access the 'Endereco' (Address) in the XML request:
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["ListaRps"]["Rps"] ["InfDeclaracaoPrestacaoServico"]["Tomador"]["Endereco"]["Endereco"]}Attribute from the Request XML
To retrieve an attribute's value, such as 'versao' (version), structure your call as follows:
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["@versao"]}Note: Use @ to fetch attribute values in the XML.
Conclusion
The integration of XML objects in FreeMarker templates significantly enhances the way NetSuite interacts with tax authorities during the PDF generation process, ensuring accurate and reliable e-document certification. Familiarizing yourself with these XML structures is crucial for optimizing PDF output.
Key Takeaways
- NetSuite provides
authRequestXmlandauthResultXmlobjects to streamline PDF generation. - Namespaces must be declared properly for accurate XML processing in FreeMarker.
- Default namespaces are replaced with consistent prefixes like
bta_default1for ease of use. - Debugging logs can help confirm the XML data available for template customization.
- Proper retrieval of values and attributes in XML is essential for effective implementations.
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
- Applied Trans Date and Period Enhancements in NetSuite 20...
Latest updates in NetSuite 2024.1 enhance Accounting SuiteApps with transaction line distribution features.
- Deployment Considerations for NFP SuiteApps in NetSuite
Understand key deployment considerations for NFP SuiteApps in NetSuite, ensuring a smooth installation and update process.
- Release Notes for Enhancements and Features in NetSuite
Explore the latest release notes highlighting enhancements and features in NetSuite, focusing on the areas of accounting, banking, and AI updates.
- SuiteApps Released by NetSuite: Enhancements and New
Discover the latest SuiteApps released by NetSuite, enhancing features in Accounting, Banking, and Order Management.
