Custom Functions

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.

Here two parameters named firstName and lastName are defined for the custom function.

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.

Here the body text editor has defined a transformation using the join-function that joins the two parameters #firstName and #lastName.

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.

Example of how to call the custom function with hardcoded parameters.
Example of how to call the custom function with parameters from 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:

Here is an example of usage in a template where the #fullName() function is used in collaboration with a pipe expression.

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.

Here is an example of the test sample data. This is also the variables used for the second example in Test Transformation showing how to call the function using variables.

Test Result

The Test Result shows the output from the Test Transformation. The result of all the above examples would look like this:

The Test Result output from all above example.