2

I have the following field definition in the Schema.XML file for a custom list definition. Per the documentation setting EnforceUniqueValues and Indexed to true should enforce a uniqueness constraint on the field, but I am able to add duplicate values across list items through the UI.

<Fields>
      <Field Type="Text" 
             DisplayName="Client" 
             Required="TRUE" 
             EnforceUniqueValues="TRUE" 
             Indexed="TRUE" 
             MaxLength="255" 
             ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
             SourceID="{$ListId:Lists/Client;}" 
             StaticName="Title" 
             Name="Title" 
             ColName="nvarchar4" 
             RowOrdinal="0" />    
</Fields>

Am I doing something wrong here? Is there somewhere else I need to set this attribute?

  • Curious. Was this in the context of a Sandboxed or Farm solution? – Brian Apr 3 '12 at 16:25
  • It was a farm solution. – JohnFx Apr 3 '12 at 18:33
3

Have you tried this for other fields than Title?

The spec for SPField.EnforceUniqueValues states that

You cannot set this property to true for a built-in field or for a site column.

Not 100% that this is valid for the declarative approachs for custom schemas, but test with another field "test" of type text and you will find out...

EDIT: - Built-in field can be set EnforceUniqueValues=TRUE. We have to also set Indexed=TRUE & AllowDuplicateValues=False. See Remarks here and answer here.

  • 1
    Ugh. I bet that's it. SharePoint is a minefield of stuff like this. – JohnFx Jun 22 '11 at 22:41
  • built-in field can be set EnforceUniqueValues=TRUE ... We have to also set Indexed=TRUE & AllowDuplicateValues=False .. Read Remarks Here >> msdn.microsoft.com/en-us/library/… – Ronak Patel Dec 13 '16 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.