Field not displaying on list with Content types Inherits="False"

9.8k views Asked by At

I've defined a content type 'related links' and set Inherits="False" and added line to remove out-of-the-box 'title' field as I don't want it showing in the view or new/edit/display forms, see (OPTION 1) in CAML below.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <!-- ===== Fields ===== -->
    <!-- Link Category -->
    <Field DisplayName="Link Category"
           Name="LinkCategory"
           ID="{654EAC00-342B-4176-9D91-613AD724F684}"
           Group="Custom"
           Overwrite="True"
           Type="Lookup"
           ShowField="Title"
           List="Lists/LinkCategoryList"
           WebId="~sitecollection" />

    <!-- ===== Content Type ===== -->
    <!-- 
    Related Links
     - Parent ContentType: Item (0x01)
    -->
    <ContentType Name="Related Links"
                 ID="0x0100c11a1db14e564574bc49a2aa9bf325d3"
                 Group="Custom"
                 Description=""
                 Inherits="False"
                 Version="0">
        <FieldRefs>
            <!-- Title (OPTION 1) -->
            <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
            <!-- (OPTION 2)
            <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
                      Hidden="TRUE" Required="FALSE" DisplayName="_hidden" />
            -->
            <!-- Link Category -->
            <FieldRef DisplayName="Link Category"
                      Name="LinkCategory"
                      ID="{654EAC00-342B-4176-9D91-613AD724F684}"
                      Required="True" />
        </FieldRefs>
    </ContentType>

</Elements>

This does remove the 'title' field from the content type but when I try to associate the content type with a list it does not display the 'LinkCategory' field in the view or new/edit/display forms. Why is it so?

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint"
      Title="Related Links"
      FolderCreation="FALSE"
      Direction="$Resources:Direction;"
      Url="Lists/RelatedLinksListDefinition"
      BaseType="0"
      EnableContentTypes="True"
      xmlns="http://schemas.microsoft.com/sharepoint/">
    <MetaData>
        <ContentTypes>
            <!-- Related Links -->
            <ContentTypeRef ID="0x0100c11a1db14e564574bc49a2aa9bf325d3" />
        </ContentTypes>
        <Fields>
        </Fields>
        <Views>
            <View ...etc...>
                <ViewFields>
                    <FieldRef Name="LinkCategory"></FieldRef>
                </ViewFields>
                <Query>
                    <OrderBy>
                        <FieldRef Name="ID"></FieldRef>
                    </OrderBy>
                </Query>
            </View>
        </Views>
        <Forms>
            <Form Type="DisplayForm" Url="DispForm.aspx"
                  SetupPath="pages\form.aspx" WebPartZoneID="Main" />
            <Form Type="EditForm" Url="EditForm.aspx"
                  SetupPath="pages\form.aspx" WebPartZoneID="Main" />
            <Form Type="NewForm" Url="NewForm.aspx"
                  SetupPath="pages\form.aspx" WebPartZoneID="Main" />
        </Forms>
    </MetaData>
</List>

As a work around I've set Inherits="True" on the content type and used (OPTION 2) in content type CAML and that hides the 'title' field, but would really like to understand what's going on here and what's the best approach to take. Thanks in advance!

PS: This post has similar question: SharePoint 2010: RemoveFieldRef and Inherits="TRUE"

PSS: When I browse via SP Manager 2010 after deploying using OPTION 1, I get the following:

  • 'Link Category' Field created correctly
  • 'Related Links' Content Type created correctly with 'Link Category' field
  • 'Related Links' list created with 'Related Links' Content Type associated
  • However 'Related Links' list has no reference to 'Link Category' Field.
1

There are 1 answers

0
Gerard On BEST ANSWER

Ok so was on my way up the garden path...

The issue why 'Link Category' Field was not being created on the 'Related Links' list wasn't related to setting Inherits="False", it was because I had not defined it in the list schema even though I'd defined it in the content type. As mentioned here:

http://msdn.microsoft.com/en-us/library/aa543576.aspx

When SharePoint Foundation creates a list instance, it includes only those columns that are declared in the base type schema of the list or in the list schema. If you reference a site content type in the list schema, and that content type references site columns that are not included in the base type schema of the list or in the list schema, those columns are not included. You must declare those columns in the list schema for SharePoint Foundation to include them on the list.

And here:

http://stefan-stanev-sharepoint-blog.blogspot.com/2010/03/contenttypebinding-vs-contenttyperef.html

One ugly thing about it is that you specify a site content type to be attached to the list based on that list definition but the framework doesn’t provision the fields in the content type if they are missing in the list – so you need to add manually all content type’s fields in the Fields element of the list schema file. This is actually what I called the fields’ redefinition issue...

So duplicated Field element below from the content type definition to list schema:

    <Fields>
        <Field DisplayName="Link Category"
               Name="LinkCategory"
               ID="{654EAC00-342B-4176-9D91-613AD724F684}"
               Group="Custom"
               Overwrite="True"
               Type="Lookup"
               ShowField="Title"
               List="Lists/LinkCategoryList"
               WedId="~sitecollection" />
    </Fields>

I can confirm that using Inherits="False" & <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" /> does remove the title field.

Here's another good link about Inherits="False" for those who stumble upon this post.

https://sharepoint.stackexchange.com/questions/2995/mysteries-of-the-contenttype-inherits-attribute