Users can learn useful validations and treatments which can be done with the Freemarker language when you use Template Transformer on the Digibee iPaaS.
Enables you to make iterations in an array (list) in JSON. Imagine this function in the creation of a dynamic elements list in the output, that transforms JSON into XML.
Syntax
<#list YourList of elements>
block of information to be iterated.
</#list>
Example
Using the input informed in the beginning of this article, you can create a dynamic elements list using the template.
Remember that the Template output is an XML in a string.
IF/ELSE
You can use this function to validate some information. Even when its fields are null or empty, there's no great impact on your data transformation.
Syntax
<#if condition> Block of information in case the condition in if is true.<#elseif Syntax> Block of information in case the condition in elseif is true.<#else> Block of information in case none of the conditions are taken.</#if>
There's no limitation for the quantity of elseif, and it's also possible to use just an if without the else - it all depends on your need.
Example
Using the input informed at the beginning of this article, you can create a validation in which the "code" field needs to be greater than 0 (zero).
Did you know the use of the function isn't limited to simple conditions? You can also use expressions to validate if the field exists (??) or if it has content (has_content).
Syntax
<#if yourField?? && yourField?has_content> Block of information if the field exists and has content.<#else> Block of information if none of the conditions is taken.</#if>
It's possible to use logical operators for a more advanced condition.
&& - for AND.
|| - for OR.
Example
Now see how to improve the validation so that the if applied in the first case is used only if the "code" field exists and has content.
This function is used to remove the blank spaces at the beginning and in the end of a string.
Syntax
${YourField?trim}
Example
Using the input informed at the beginning of this article, you can remove the blank spaces at the beginning and in the end of the "description" field".
This function is used when the field must have a determined size.
Syntax
${YourField[0..9]} 0 = initial value9 = final value
Example
Using the input informed at the beginning of this article, you can determine for the field to have 10 characters only, even if it has a greater size.
A good practice applicable to this function is to use IF/ELSE to validate the desired size for the field. That way, you avoid errors if the field is smaller than the established value.
If the desired format isn't accepted by your system, you can define the necessary number for formatting through the "number_format" tag. It allows you to customize the number formatting.
Syntax
<#setting number_format="0.##">${yourField}
The hashtags(#) define the quantity of decimal places to be used.
Example
Using the input informed at the beginning of this article, you can format the value to be in the legacy system standard.