Avoid Duplicate Item Names in Sitecore

In Sitecore, avoiding duplicate item names is crucial to maintain a well-organized content structure and to prevent conflicts within the content management system.

This becomes even more important if you are using Sitecore Content Serialization (Sitecore CLI) as the serialization pull and or push command will fail without any meaningful error. Therefore, we must ensure that there are no duplicate item names under same parent ever.

Duplicate item names on the same level are not supported by the CLI, even if such items are under ignored nodes.

Ref: https://doc.sitecore.com/xp/en/developers/100/developer-tools/sitecore-content-serialization-configuration-reference.html


Below are a few steps that we can use to avid them in the first place, but in case you already have duplicates I have created another blog post that outlines a few ways you can fix them fast.

Step 1: Ensure AllowDuplicateItemNamesOnSameLevel is set to false in sitecore config

Starting Sitecore 9 the duplicate item names are restricted at the same level, but it is possible that this setting is overwritten by your custom configurations. To ensure AllowDuplicateItemNamesOnSameLevel is set to false simply check showconfig.aspx on your CM instance. You can open showconfig by

  1. Login to Sitecore and then Control Pannel -> Administration tools -> Show Config
  2. Directly opening the show config URL https://{cm_url}/sitecore/admin/showconfig.aspx

On the showconfig.aspx page search for AllowDuplicateItemNamesOnSameLevel and make sure it is set to false.

<setting name="AllowDuplicateItemNamesOnSameLevel" value="false"/>

If it is set to true, try looking for a custom config file that is overwriting this setting and change it there. You should not be changing any config file shipped with Sitecore.

Step 2: Guide your content editor/authors to watch out for duplicate items

With step 1 in place there are still cases when you will see duplicate items in cases such as

  1. Sitecore package is installed
  2. Item is created through code

Therefore, it will help if the team/people creating and managing content are aware of this and can fix them as soon as they appear.

Step 3: Create custom events to ensure duplicate items are not allowed

To absolutely make sure that there are no duplicate items at same level the bullet proof option is to tap into these events and then have your custom code take care of it

  1. item:copying
  2. item:creating
  3. item:moving
  4. item:saving

In your custom even code you can handle the item naming by either appending incremental number to the item name or have some other logic ensuring that item names are always unique. I will write another blog post to share code example of how that can be achieved.