Transforming Data with Sitecore DEF

When transferring data between systems while some data will map directly you inevitably will come across data objects that need be transformed from the source format into a format that is compatible with the target object. Sitecore Data Exchange framework provides a mechanism and flexibility to reuse to Transform source data objects into the required format for the target data object.

A Value Reader allows you to read a value from a Source object. While it can read the value as is, they can also be used to transform the value. With each version of DEF Sitecore has provided a number Value Readers OOTB.

With DEF version 1.4.1 you have access to the following values readers:

DEF141_DataReaders

  • Array Value Reader – basically this can be used to read a value from an array. You just need to specify the Position in the array of the value you wish to read.
  • Constant Value Reader – can be used to read a constant string value. The Value field is returned when the reader is used. The Value Type field specifies the type the value is converted to before being returned. The default value is System.Object, meaning the value is not converted.
  • Enum Value Reader – can be used to read a value as a member of a .Net enum. The Enum Type field you must specify a .Net enum to read. The value reader will support either an Int or a String value. It will attempt to convert the value provided into the enum member with a matching name. If a match isn’t found on the enum null is returned.
  • Fallback Value Reader – can be used to specify additional value readers in the event that no value is read. The Readers field is where you specify the value readers that are used until a value is read. The fallback value reader will loop through the readers until a non-null value is read.
  • ISO Date Value Reader – can be used to read a DateTime object as an ISO date. The Convert to UTC field determines if the DateTime that is read is expressed as UTC or not. The Include Ticks field determines if the DateTime includes ticks or not.
  • Method Value Reader – can be used to invoke a method on a .Net object and return the results. The Method Name field specifies the name of the method that is invoked. The Is Extension Method field determines if the method is an extension method or not. Extension Method Type field is the type in which the extension method is defined in if it is an Extension. Parameters can be passed to the method by adding child items to the value reader.
  • Now Value Reader – can be used to read the current DateTime. The UTC Date field determines if the DateTime read is expressed as UTC or not.
  • Property Value Reader – can be used to read the value of a property from a .Net Object. The Property Name field specifies the property whose getter is invoked.
  • Raw Value Reader – can be used to read the source object.
  • Sequential Value Reader – can be used to read a value from a source object by invoking a series of values readers, where the source object passed to each subsequent value reader is the object that was read by the previous value reader.
  • Value Accessor Value Reader – uses the value reader assigned to a value accessor. The Value Accessor field specifies the value accessor whose value reader will be used.

If you are on Sitecore 9 and running DEF 2.0, Sitecore added the following common Value Readers to the framework:

DEF20_ValueReaders

  • Code To Description Value Reader – can be used to convert an integer value into a string value description. A Code Definition set allows you to configure the mappings in Sitecore.
  • Collection To String Value Reader – you can combine the elements in a collection using a specific delimiter.
  • Constructor Value Reader  – can be used to call a constructor and return the created object.
  • Convert Collection Members Value Reader
  • Convert Type Value Reader – reader converts a source object to a different type by allowing you to specify a target type.
  • Culture Info Value Reader – The source object must be a valid culture identifier and the reader returns a System.Globalization.CultureInfo object.
  • Date Time Value Reader – reader returns a date/time object. You can specify a string format and the reader expects the source object to be a date in the specified format. The Read Date Only if ticked excludes the time, unticked includes date and time.
  • Guid As String Value Reader – can be used to return a formatted string that represents the value from a guid.
  • Guid Value Reader – the reader used to returns a Guid object and can be used to check of an object it a Guid.
  • MD5 Value Reader – used to convert the source object to MD5 hash value.
  • Number to DateTime Value Reader –  can be used to convert a Unix timestamp (epoch) to a date/time object.
  • Static Method Value Reader – the source object to a static method and returns the method’s return value.
  • String Split Value Reader – can be used to split a string into an array. You can specify the number of elements to return and the split separator.
  • Truncate String Value Reader – used to truncate a string and you can specify the Length of characters to be returned.
  • Value Accessor Value Reader – uses the value reader from a specified value accessor to read a value.
  • Values to Array Value Reader – can be used to read multiple values from a source object into an Array by specifying the Value Accessors.

Provider Specific Readers

Each of the providers Sitecore, CRM, Salesforce and xConnect also include providers so you might want to check those as they might have already created something and save you from having to create your own custom reader.

So how do you use these Readers in DEF?

Well the beauty about DEF is its flexibility and so it provides you with a number of options and it might depend on your particular use case:

  • Use the Reader to transform Source Value when writing to the Target Value.
  • Use the Reader to Transform the Source Value everytime it is read.
  • Use the Reader to Transform the Source value when you are mapping to the Target Value.

More Info

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s