Sitecore DEF + SXA — Part 1: Handling duplicate items when resolving item

Jack Spektor
3 min readJun 19, 2022

Hello friends. Took some time off writing on Sitecore topic for a while, but back to business now, so… here we go again!

Today I’m going to share some experience from using Sitecore DEF.

For those who don’t know its a Sitecore framework that helps to simplify the process of data migration between different systems.

The framework supports different data sources as the source of the migration (Sitecore, DB, custom), as well as it supports data transformation during migration.

In my case the task was to migrate the data between two Sitecore systems — in particular the task involved transforming standard Sitecore page into SXA page with various component on it.

To migrate an item as part of DEF pipeline it needs to be resolved first.

For this Sitecore DEF provides an OOTB action called “Resolve Sitecore Item Pipeline Step”

It allows to find an item in source system by making a search with a fieldname and resolving a corresponding item in the Target system.

However the requirements were to map the item by name (e.g. retaining the same item name during the migration), as well as we faced the issue of duplicate item names — turns out that if there are two items in the source system with same item names — then DEF was failing to migrate them.

To solve this we’ve decided to extend the pipeline action and do some modifications to the item resolving code of DEF:

Here we are explicitly making a search by _name field in the index, as well as before returning item we make another check to make sure that item name is exactly the same — this is because if there are 2 items in the index that contain the search term then we could potentially return incorrectly resolved item.

Another change was the moment we create the resolved item in the target system. In some cases the item is already created before, but the index is not updated yet, which causes DEF to incorrectly believe that item was not created yet.

Now if we already created the item before we try to resolve it with Sitecore data provider (opposing to Sitecore search).

The full class source code you’ll be able to find here:

Hopefully this small code snippet would useful for happy Sitecore DEF users.

Happy coding!

P.S: In next article I’m going to cover some experience with creating SXA datasources and components with DEF actions.

--

--

Jack Spektor

Sitecore MVP 2018–2020, Sitecore Developer in AKQA, traveler and lover of life.