Customizing E-Document PDF Templates for Brazil
To access the Brazil Certification Tax Authorities SuiteApp documentation in Brazilian Portuguese (Português do Brasil), see Brazil Certification Tax Authorities.
When customizing PDF templates in the Brazil Certification Tax Authorities SuiteApp, you can retrieve values directly from the original XML used during e-document certification. You can reference both the request and response XML data exchanged with the tax authority using FreeMarker expressions. These expressions let you include values that may not be exposed by default in the e-document record.
FreeMarker is a template language that lets you insert dynamic content and work with XML data in your PDF templates. For more information, see HTML and FreeMarker for Scriptable Templates.
XML Objects in the Template
When generating a PDF, NetSuite makes the following objects available for use in FreeMarker expressions. These objects contain the XML data exchanged with the tax authority during e-document certification.
Object |
Description |
---|---|
|
The full XML request sent to the tax authority. |
|
The full XML response received from the tax authority. |
Namespaces in XML
If the XML includes namespaces, declare them at the top of the template using the ns_prefixes
directive.
<#ftl ns_prefixes={
"soap": "http://schemas.xmlsoap.org/soap/envelope/",
"ns4": "http://nfse.abrasf.org.br"
}>
Use the declared prefixes in your expressions according to the XML tag definitions. For example, enter soap:Envelope
, not Envelope
.
Default Namespaces and XML Content Handling
-
Default Namespaces Replacement
When the XML contains default namespaces (namespaces without prefixes), the system replaces them internally with prefixes like
bta_default1
,bta_default2
, and so on. The number increments for each distinct default namespace URI.The namespace prefixes such as
bta_default1
are consistent across different environments. You can rely on these prefix names when creating and maintaining your templates.To access these XML elements, include the new prefixes in your
ns_prefixes
directive and use them in your XPath expressions.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
Some response XML files may contain CDATA sections within the original XML. If these CDATA sections include embedded XML content, the XML content retrieved through
authRequestXml
orauthResultXml
objects may not match the original raw XML source.Example of embedded XML in CDATA:
<Response> <![CDATA[ <InnerXML> <Value>Example</Value> </InnerXML> ]]> </Response>
To verify the exact XML available for customization, edit the ECS MR Message Queue Service Map/Reduce script deployment, and set the log level to Debug. For more information, see Map/Reduce Script Deployment Record.
During e-document certification, check the logs for entries where the
${alias}
placeholder can be eitherauthRequestXml
orauthResultXml
. These log entries display the XML content available inside the PDF templates, as shown in the following:TaxAuthorityPdfGenerator - renderTaxAuthPDF: ${alias} data source before PDF render
XML Values Retrieval with FreeMarker
You can use the following examples to retrieve values from different parts of the XML.
Value from the Response XML
This example demonstrates how to retrieve the “RazaoSocial” (Company Name) element from the XML response received from the tax authority.
${authResultXml["soap:Envelope"]["soap:Body"]["ns4:ConsultarLoteRpsResponse"]
["ConsultarLoteRpsResposta"]["ListaNfse"]["CompNfse"]["Nfse"]["InfNfse"]
["PrestadorServico"]["RazaoSocial"]}
Value from the Request XML
This example demonstrates how to retrieve the “Endereco” (Address) element from the XML request sent to the tax authority.
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["ListaRps"]["Rps"]
["InfDeclaracaoPrestacaoServico"]["Tomador"]["Endereco"]["Endereco"]}
Attribute from the Request XML
This example demonstrates how to retrieve an attribute value within the XML request. In this case, the attribute is “versao” (version), but you can reference other attributes in the same way.
${authRequestXml["EnviarLoteRpsEnvio"]["LoteRps"]["@versao"]}
Use @
to retrieve attribute values in the XML.
Related Topics
- Brazil Certification Tax Authorities
- Brazil Certification Tax Authorities SuiteApp Installation
- Roles and Permissions for Brazil Certification Tax Authorities
- Finding Predefined E-Document Template Files for Brazil
- Associating Certification Service Operations with E-Document Templates in Brazil
- Enabling E-Document Validation on Certification Service Operations in Brazil
- Certification Custom Fields for Brazil
- Receiver Acknowledgment
- Adding the Certification Web Services Availability Portlet to a Dashboard
- Brazil Certification Tax Authorities SuiteApp Best Practices and Known Limitations