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.

·3 min read·4 views·View Oracle Docs

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:

freemarker
<#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:

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

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:

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:

freemarker
${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:

freemarker
${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:

freemarker
${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 authRequestXml and authResultXml objects to streamline PDF generation.
  • Namespaces must be declared properly for accurate XML processing in FreeMarker.
  • Default namespaces are replaced with consistent prefixes like bta_default1 for 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?
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 →