2
votes

For a sitecore project, I need to validate the uniqueness of item names (to avoid url overlap)

It is possible to add the 'Duplicate name' Item validation rule to the item's template (to see these options, make sure 'show standard fields' is selected in the 'view' tab, in the content editor ribbon)

apply the duplicate name validation rule

However, the options available here are to add the validation rule to the

  • Quick Action bar
  • Validation Button
  • Workflow Validation Rules

Should I apply it as a workflow validation rule, and enable workflow (for all my content items)? That would work, but it seems like a lot of effort for the end user if they have to use workflow for something.

What I want to achieve is to simply show a validation message when the user tries to save the item (and uses a name which is already taken). Basically in the same way field validators work in sitecore

None of these choices seem to achieve this effect.

So my question is, what is the easiest way to achieve this?

3

3 Answers

2
votes

Validation Bar Validation Rules - Runs in the bar to the right of the content editor.

You may want to override the item:saving event or the contenteditor:save command. Take a look at item:saved. The OnItemSaved event triggers the Rules for an item.

If you change the dialog in the content editor or update the events, you'll want to make sure that your logic applies to specific parts of the content tree - i.e. sitecore/content/home, and/or possible security role.

I agree about the amount of effort regarding workflow, but in certain cases, may make perfect sense for this and other validation requirements.

0
votes

I have a blog post out for this which uses the item create / save event. This was implemented and tested with Sitecore 7.2. Here's the config used:

<sitecore>
  <events>
    <event name="item:creating">
      <handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemCreating" />
    </event>
    <event name="item:saving">
      <handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemSaving" />
    </event>
  </events>
</sitecore>