Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

The article here : http://msdn.microsoft.com/en-us/library/ee536168.aspx describes how to set the unique field using code, I guess you could put this code in the feature receiver activated event.

Is there an easy way to define field uniqueness in the XML field definition.

My first guess would be :

   <Field
  Type="Number"
  ID="{01FC2C92-07A1-4AE3-9D28-C13B22A49804}"
  Name="ID"
  DisplayName="ID"
  StaticName="ID"
  Indexed="TRUE"
  EnforceUniqueValues="True"
  Group="OrgStructure"
     >
  </Field>

But I'm getting this error:

Error occurred in deployment step 'Activate Features': This field must be indexed to enforce unique values

Update:

I realized I was setting this in the raw field definition, not in the list instance where I think it would be more suitable, so I added All fields of the content type to the fields collection for the list instance, and set the property there, no error during deployment, but it ignores the unique binding.

share|improve this question
    
Not sure how I solved the issue, but the problem was not in the field definition. As it turns out the unique constraint can be enforced at the field definition level. –  user879 Dec 7 '10 at 18:10
add comment

2 Answers 2

Just add Indexed="TRUE" in the <Field> element

share|improve this answer
add comment

Try using this utility to generate the markup for the field definitions and content types which you have created in SharePoint 2010 using the UI. This utility can generate the ferature markup which you can later incorporate in your solution as is:

http://spwcmfeaturegen.codeplex.com/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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