I ran into an issue when cleaning up two pairs of items like so:
Parent item
Reference Item 1
Similar Reference Item 1
[delete and relink toReference Item 1
]Reference Item 2
Similar Reference Item 2
[delete and relink toReference Item 2
]
The above items are part of a list of items which are used as options for a checklist field; specifically, a list of timezone items which are the source for a checklist field on an event item.
Prior to the cleanup, I had an event item that had all of the timezone options selected. The image below is what that checklist field looks like after performing the cleanup. Notice how the last two options say [Not in the selection List]
and that they are already selected as the 3rd and 4th options. After inspecting the raw value of the field, I can see that those two IDs are in fact selected twice. Normally, the UI wouldn't let you selected the same option twice in a multilist-type field, so this is a problem:
It seems that relinking during item deletion does not take into account if the field we are updating is already also referencing the item that we are relinking to.
That is, prior to the cleanup, the event would have had these options selected in the checklist field:
Reference Item 1
Similar Reference Item 1
Reference Item 2
Similar Reference Item 2
And after performing the relinks, we wound up with this:
Reference Item 1
Reference Item 1
Reference Item 2
Reference Item 2
Note that I don't have the option of removing the breaking links (instead of updating) during deletion because it's not always guaranteed that event items will be referencing both items in a set. Whether an event was previously linking to one or both of the options in the set, it always needs to result in there being a single link to the remaining item, e.g. when Reference Item 1
or Similar Reference Item 1
or both are selected, the end result should be that Reference Item 1
is the only selected option.
Does Sitecore not take this scenario into account when relinking? I can understand why it wouldn't, because Sitecore can't make assumptions about what the order of the selected options should be. If merging two IDs into one, which one should be removed? That's not Sitecore's call. Therefore, it keeps both in their respective places and simply updates the ID(s). Then again, in the case of a checklist field, the selected options aren't able to be re-ordered like a true multilist field, so I wouldn't expect to see this problem for checklist fields.
Further, if this observation is correct, isn't the implication that we should be performing a uniqueness check whenever we enumerate multilist-type fields?
What are my options? It seems that the instances of the issue would need to be resolved case by case or via a script. Either way, it would have been helpful if a dialog box warned me that this was going to happen.