Thursday, June 17, 2021

Using the Cast Component in Liquid Data Mapper

Liquid Data Mapper is a powerful data mapping tool supporting advanced transformation of data in a variety of formats such as CSV, Database, EDI, JSON, Web Services and XML.

Using the Cast Component

The Cast Component provides a mechanism for converting data types which cannot be automatically converted.

For example, in EDI the 'Date of preparation' field requires a 6 digit date such as '170621'.

However, if we connect a Const Component with this sting value we will see an error message when we run the transform:

'The format of the value '170621' is incorrect for casting from a String to Date.


In order to support this we can use the Cast Component.

Cast Component Properties

After adding the Cast Component, we need to set the cast properties. To show the properties dialog, we can either double click the component, right click the component and select 'Show Properties' or use the short cut 'Shift+F4'.

We will need to change the Cast Type to be 'Date' or 'DateTime' and set the Casting rule to be 'Customizable DateTime'.
 
Then we can set the Format Specifiers to match the format of the input string data 'ddMMyy'. The format string follows the rules of the Microsoft .Net Standard date and time format strings.

Cast Component

Now when we run the transform, the string value is correctly written in the required EDI date format.

Further Reading

Please see the data mapper documentation for additional information about casting various data types in Liquid Data Mapper.

Download a Free Trial of Liquid Data Mapper:
https://www.liquid-technologies.com/trial-download