Hi everyone!
I hope you are doing great!
I'm working on an Advanced PDF/HTML Template and need to create a mask for Brazilian info called CNPJ.
The raw data is XXXXXXXXXXXXXX, and I have to format it as XX.XXX.XXX/XXXX-XX.
Then, I used this code to format it:
<#assign unformattedCNPJ = record.entity.custentity_enl_cnpjcpf>
<#function formatCNPJ unformattedCNPJ>
<#return unformattedCNPJ?substring(0,2) + "." + unformattedCNPJ?substring(2,5) + "." + unformattedCNPJ?substring(5,8) + "/" + unformattedCNPJ?substring(8,12) + "-" + unformattedCNPJ?substring(12,14)>
</#function>
<#assign formattedCNPJ = formatCNPJ(unformattedCNPJ)>
Then, the validation returns this error:
Line 151 = <#return unformattedCNPJ?substring(0,2) + "." + unformattedCNPJ?substring(2,5) + "." + unformattedCNPJ?substring(5,8) + "/" + unformattedCNPJ?substring(8,12) + "-" + unformattedCNPJ?substring(12,14)>
Error on line 151, column 17 in the template.Detail...
?substring(...) argument #2 had an invalid value: The index mustn't be greater than the length of the string, 0, but it was 2.
----
FTL stack trace ("~" means nesting-related):
- Failed at: #return unformattedCNPJ?substring(0, ... [in template "template" in function "formatCNPJ" at line 151, column 17]
----
Error on line 154, column 9 in template.Detail...
The following has evaluated to null or missing:
==> formatCNPJ(unformattedCNPJ) [in template "template" at line 154, column 34]
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: #assign formattedCNPJ = formatCNPJ(un... [in template "template" at line 154, column 9]
----
-------------------------------------------------------
Line 154 = <#assign formattedCNPJ = formatCNPJ(unformattedCNPJ)>
"Error on line 154, column 9 in template.Detail...
The following has evaluated to null or missing:
==> formatCNPJ(unformattedCNPJ) [in template "template" at line 154, column 34]
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: #assign formattedCNPJ = formatCNPJ(un... [in template "template" at line 154, column 9]
-----------------------------------------------------------------
Line 158 : <td class="addressheader" colspan="7"><span style="font-size:12px;"><strong>${record.custbody_ava_customercompanyname}</strong><br /><b>CNPJ: </b> ${formattedCNPJ} </span></td>
Error on line 158, column 156 in template.Detail...
The following has evaluated to null or missing:
==> formattedCNPJ [in template "template" at line 158, column 158]
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${formattedCNPJ} [in template "template" at line 158, column 156]
----
The thing is that after the validation, if I ignore this error and save the template, it works fine with the correct mask.
But I'm not able to switch from Source Code to WYSIWYG mode, due these errors.
Looks like that when we are validating the CNPJ , we don't have this info yet. But when it found it on record, it works.
How could I handle this to validate without errors?
Thanks a lot!