Friday, June 16, 2017

Liquid Data Mapper - Sub Functions

The Liquid Data Mapper makes building complex data transformations quick and easy, but before you start there are a few basic concepts you need to learn.

Custom Sub Functions are a good way to keep your transforms maintainable and easy to read by creating a library of custom components with reusable functionality.



Liquid Data Mapper - Sub Functions
Liquid Data Mapper - Sub Functions

In this example we want to tidy up our customers first name and last name, by capitalizing the first letter. The transform to do this is fairly easy to follow, it takes the first letter and makes it upper case, it takes everything after the first letter and makes it lower case and concatenates the 2 bits back together.

Although its simple there are a few parts to it and we need to use it more than once, so it ends up making our transform look quite complex.

The solution is to create a Sub Function.

Sub Function Sample - CapitalizeFirstLetter

Liquid Data Mapper - Sub Functions
Liquid Data Mapper - Sub Functions
This is a simple sub function that will capitalize the firth letter of the input string and return it as an output string.

The name and type of the sub functions inputs and outputs can be configured. You can also add more inputs and outputs as required.

It is important to name the sub function. This can be done by clicking on the canvas and setting the ‘Name’ Property in the properties window. This is the name that will then be used to find the sub function.

Sub functions can also make use of other sub functions.


Liquid Data Mapper - Sub Functions
Liquid Data Mapper - Sub Functions
We can now use the Sub Function 'CapitalizeFirstLetter' in our original transform to massively simplify the diagram but with identical functionality.


Tip: Execute the transform by pressing Shift-F5. Debug the transform by pressing F5 to start the debugger, then:
    F11 - Step Into
    F9  - Set break point
    F5 - Run (stops on break points)



A free trial of the Liquid Data Mapper is available from:
https://www.liquid-technologies.com/trial-download