2

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.

  • 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
3

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

1

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/

0

TRUE/FALSE values should be UPPERCASE.

Indexed="TRUE"
EnforceUniqueValues="TRUE"

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.