May 28, 2009

Content Types Inheritance: How to remove a field inherited from the parent in CAML

As you know, you can inherit from a Content Type in CAML simply in specifying a valid ID. Typically, to inherit from an existing Content Type, you have to respect the following rule: Parent content type ID + "00" + hexadecimal GUID
e.g.: 0x01 (ID of the Item Content Type) + 00 + 21D64BFAA43542c0B10CB673D6445495

The problem when inheriting is that you don't specially need all fields from the parent. To remove a field inherited from the parent, you have to use the RemoveFieldRef tag in specifying the ID of the field.

In the following example, I inherit from the Item Content Type but I add two new fields (Year and Amount) and I remove the Title field:


<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <ContentType ID="0x010021D64BFAA43542c0B10CB673D6445495"

          Name="Budget"

          Description="Create a new budget"

          Version="0"

          Group="My Inherited Content Types" >

        <FieldRefs>

            <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"/>

            <FieldRef DisplayName="Year" ID="{6FC684B4-CE06-480f-A8A5-E62277AAFB79}" Name="Year_MICT" />

            <FieldRef DisplayName="Amount" ID="{A4D2A891-27D6-4f5d-B5C2-4A9AC4D2000D}" Name="Amount_MICT" />

        </FieldRefs>

    </ContentType>

</Elements>


Have a look on the following MSDN links to understand how Content Types work:
Base Content Type Hierarchy: http://msdn.microsoft.com/en-us/library/ms452896.aspx
Content Type IDs: http://msdn.microsoft.com/en-us/library/aa543822.aspx
Creating Content Types Based on Other Content Types: http://msdn.microsoft.com/en-us/library/ms460224.aspx<

No comments: