Quite often there are cases in Message Mapping, where one condition defines values for multiple target fields.
The developer is required to write one custom function per target field for checking the very same condition and assigning the required values. This design made it difficult to maintain the mapping.
Cloud Integration now enables a new feature that allows a custom function module to compute and return the values of multiple target fields together – a custom groovy function that is added to a message mapping is used for this purpose.
The custom groovy function allows you to assign values to as many output parameters as needed. You can check the condition in the function only once and assign values to multiple output parameters. These output parameters can then be assigned to the corresponding target fields via the graphical representation in the defined order.
The computation happens only once in the custom function module.
Step wise procedure of how to add a custom groovy function to message mapping can be found here.
The function signature is as follows:
def void <Function Name>(<data type 1> <Input Param1>,…,
<data type N> <Input Param N>, Output <Output
Parameter 1>,…, Output <Output Parameter N>)
The place holder for the return type of the function is set by default to void.
The actual return parameters are defined inside the brackets after the input
The input parameter can only be an Array of type Float, String, Boolean and Int. Based on how the source context is set, the input can be collection of nodes instead of one node. In order to be able to handle all cases, we expect input parameters as arrays. Refer to the sample function below for an example.
The return parameter is only of type Output. Output is a list object so it can be assigned multiple values if the scenario demands. The multiple values of the output parameters will be assigned as multiple occurrence of the target field.
You can add as many number of input and output parameters to this function module.
In the example below, we are calculating the various components of the salary of an employee based on his location. Finally, after all the calculations, the function shall return all the 3 components of the salary together:
Available in Eclipse tooling since July 2017
Web Tooling: Function signature is supported since July 2017 and graphical representation support is available from October 2017.