CET Stories: The Duplicate Field Conundrum

CET Stories  is a series of stories of cases where the Content Export Tool was able to solve problems that otherwise would have required an immense amount of labor. These stories will demonstrate the capabilities of the tool and provide examples of when and why you should use the Content Export Tool. 

I’m not sure how this happened to begin with, but we ran into an issue on one of my sites where a component had a bunch of duplicate fields, and it was causing problems because the author would fill out one field, but it wouldn’t get used because the duplicate field was overriding it. The author could resolve this by making sure that all pairs of duplicate fields had the same value, but this is tedious and shouldn’t need to be done. The simple answer was to remove the duplicate fields, however the template was being used in over 1000 places and the client was very concerned that if I just deleted the duplicate fields, content might get lost if the field that was deleted was the one that had content in it and not the empty one. Which one of the two identical fields was filled out was inconsistent; on one item, FieldName (1) was filled out and FieldName (2) was blank, but on another item (1) was blank and (2) was filled.

There were a grand total of six pairs of duplicate fields. Yikes.

The solution:

I used the Content Export Tool to get a report of every item of that template type, with all six of those fields. Because the duplicates had the same name, I couldn’t select the fields by name (since if I selected FieldName and FieldName, I would only get one field back and the second one would be ignored). Instead, I used the IDs of each field to get the data:

fields.PNG

The report it gave me was a little messy, but it worked. All of the data was there, the only issue was that the header row was messed up. The Content Export Tool does not expect different fields to have the same name, so duplicates are ignored. There were twelve columns of data but only six headers.

headers.PNG

This was easy enough to parse out though. I could understand the data, but I had to modify the headers in order to be able to re-upload in the Import feature. Even though I input IDs in the export, the CSV displays names instead as that’s more readable for the user, but in this particular case that actually was not what I needed. So I just did some quick edits to put the appropriate field IDs as the headers:

fixedheaders

Then I went through my CSV and everywhere FieldName (1) was filled and FieldName (2) was blank (or vice versa), I copied the value into the blank field. Once this was done, I saved my CSV and uploaded it to run the import. I double checked a handful of items and sure enough, all of the duplicate fields now had the same data! We could now delete the duplicate fields from the template and be confident that no content would be lost.

Author: ericastockwellalpert

.NET Developer and Sitecore MVP 2019-2020

One thought on “CET Stories: The Duplicate Field Conundrum”

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 )

Google photo

You are commenting using your Google 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