In DocuMotor it is possible to define custom functions. These custom functions apply the transformations defined. This reference contains a description of how a custom function is configured.
It is possible to use custom functions in other transformations e.g. in Templates. When calling a custom function it is required to use #
in front of the function name. For example if a function is named: fullName
it should be refered in the transformations as #fullName()
Parameters
To be able to pass on parameters to the custom functions it is needed to define the parameters in the parameters block of the function page. Each parameter needs a name that should be used when writing the function’s transformation in the body text editor.
When referring to these parameters in the body text editor it is required to use #
in front of the parameter names. So when referring to the parameters defined in above image it should look like this #firstName
and #lastName
.
By Value vs By Expression
A parameter can either be passed as by value or by expression. When a parameter is passed by value, it is evaluated when the function is called and the result is passed to the function. When a parameter is passed by expression it is not immediately evaluated on function call and instead evaluated in the scope where it is read in the function body.
Body
The body text editor is where the JMES transformation, that the custom function applies, is configured. This transformation should refer to the parameters defined in the parameters block.
As seen in above image, the parameters are referred to by using #
in front of the parameter names.
Test Transformation
The Test Transformation text editor is used to test how to call the custom function. It is both possible to use hardcoded parameters or parameters from the Test Sample Data text editor. Below is two examples of how to test call the function with both hardcoded parameters and parameters from the Test Sample Data.
Note: When calling a custom function (e.g. in Templates) and referring to previously defined variables with the $ operator
, it is important to keep in mind that this operator can end up referring to different variables inside the custom function’s own transformation. Therefore it is strongly recommended using a pipe expression. Relevant example can be seen in below image:
Test Sample Data
The Test Sample Data text editor should contain an example of some sample data to test how to use data variables when calling the custom function.
Test Result
The Test Result shows the output from the Test Transformation. The result of all the above examples would look like this: