Archive for February, 2012

Every once in a while you run across something that Google just doesn’t turn up results for and you wonder, “Is it just so easy that everybody is getting it and I’m about to have a V8!?” Well, maybe I’d better drink it down (I do have a V8 V-Fusion for lunch today).

I’m working on developing a custom content type to make the definition and deployment of a custom list easier. I have done this in the past with Visual Studio 2007 for MOSS 2007, but this is the first time I’ve done it with Visual Studio 2010 for SP2010. When trying to deploy my solution, I was getting the following deployment error:

Error occurred in deployment step 'Activate Features': The field with Id {fa564e0f-0c70-4ab9-b863-0177e6ddd247} defined in feature {[my feature GUID]} was found in the current site collection or in a subsite.

Strange! Never had this problem before. Poking around led me to MVP Rob Windsor’s Weblog on Custom Content Types and Inherits in SharePoint 2010. Rob does a good job noting some of the peculiarities of the Inherits boolean attribute on the ContentType node.

Visual Studio 2010 automatically sets the Inherits property to TRUE in your custom content type definition when you start your project using the SharePoint 2010 Content Type template because it sets up the project to extend an existing content type. I had previously always omitted this attribute which made it default to a value of FALSE.

Setting Inherits = "TRUE" in the ContentType node made it such that my List Definition also got Inherits = "TRUE" when I created it using the List Definition From Content Type template. Since I have a List Instance in the list definition, the list is automatically created when the feature is activated. With Inherits set to true, my list automatically gets all of the fields of its parent. In my case, the parent was Custom List; which means the Item content type (0x01).

However, I need to change the definition of the Title field as such:

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Registrant" Type="Text" Required="FALSE"/>

Hence the reason for the error. “fa564e0f-0c70-4ab9-b863-0177e6ddd247” is the GUID of the Title field for the Item content type. Since I’m inheriting, the field already exists. I can’t define it again. However, I can and should add this as a FieldRef as follows:

<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Registrant" Required="FALSE"/>

So, how do I change the display name and the requirement for the field? As Rob pointed out: Stop inheriting. Soon as I change to Inherits = "FALSE" and get rid of the Field definition, the feature activates without problem.

Moral of the story: If you are wanting to modify an inherited field when doing a custom content type, don’t forget to change the Inherits attribute to FALSE. Otherwise, you’ll get an error message similar to the one above.


Read Full Post »