Issues with Content Types

 

I have been doing a lot of work with custom content types and content type event receivers lately.  I have run in to a few bugs that I think are worth noting.  Before I get in to the details, I would like to say that some of the issues that I experienced were, quite simply, because of a lack of attention to detail on my part.  That being said, I'm quite sure that I'm not the only person that has ever experienced these issues.

 First of all, here are the steps to recreate the problem:

  • 1. Create a new set of site columns using the Microsoft Feature 12TEMPLATEFEATURESfields as a template. (see fig. A)
  • 2. Create a new content type that uses these fields (see fig. B)
  • 3. Apply these fields to a custom list definition see fig. C)
  • 4. Add the list to a site, when you try to add a new item there should be fields missing from the newform.aspx page.

Fig. A)

            <Field ID="{76d8a613-d5b1-4c80-a5c4-b0ad2c159743}"

               Type="Text"

               DisplayName="Field1"

               Description="Test Field 1"

               Required="FALSE"

               Group="Custom Columns"

               StaticName="Field1"

               Name="Field1">

      </Field>

      <Field ID="{F4C72115-5BAF-47ce-BD10-1344277DCB01}"

               Type="Text"

               DisplayName="Field2"

               Description="Test Field 2"

               Required="TRUE"

               Group="Custom Columns"

               StaticName="Field2"

               Name="Field2">

</Field>

 

 

Fig. B)

<ContentType ID="0×0100ff35ff607de941ff85edc7e2e52d5ba4"

      Name="TestType"

      Group="Test"

      Description="Test Type 1"

      Version="0">

    <FieldRefs>

      <FieldRef ID="{76d8a613-d5b1-4c80-a5c4-b0ad2c159743}" Name="Field" />

      <FieldRef ID="{F4C72115-5BAF-47ce-BD10-1344277DCB01}" Name="Field2" />

    </FieldRefs>

 </ContentType>

 

Fig. C)

Fields:

            <Field ID="{F4C72115-5BAF-47ce-BD10-1344277DCB01}" Type="Text" DisplayName="Some Text" Description="" Required="FALSE" Group="Custom Columns" StaticName="Field2" Name="Field2" Customization="" SourceID="{5405662c-cce9-45d2-a057-9389a9b8e8f1}" ColName="nvarchar12" RowOrdinal="0" />

      <Field ID="{76d8a613-d5b1-4c80-a5c4-b0ad2c159743}" Type="Text" DisplayName="Some Text" Description="" Required="FALSE" Group="Custom Columns" StaticName="Field1" Name="Field1" Customization="" SourceID="{5405662c-cce9-45d2-a057-9389a9b8e8f1}" ColName="nvarchar13" RowOrdinal="0" />

So why are these fields not showing up on your forms?  Well, it may seem a little bit nitpicky on the part of SharePoint, but for some reason all of the fields have to match exactly what you defined in the xml file that created the site columns.  For instance, Field2 doesn't show up because the column definition says that it is required but the list schema says that it is optional.  Field1 won't show up because the "Name" property doesn't match in the column definition and in the FieldRef of the content type.  In fact it won't even show up in the content type.  If you delete and re-add the content type, through the interface, it creates a new content type that inherits from your content type and fixes some of the issues that were initially present.  This is why all of the fields will show up the second time around (except the fields that are incorrect in the content type definition). 

So, be careful when developing content types.  And remember, with the exception of the display name, all field properties have to match, exactly, in the three places where they are used.

Leave a Reply