SharePoint 2007 and the mysterious ever required field


Today is trouble solving day at a customer. One of the issues was a SharePoint Library on their Intranet having a required field, even though Require that this column contains information was set to “No”.

So I opened up SharePoint Manager 2007 to inspect the SchemaXml:

<Field Name="Attached_x0020_to" FromBaseType="FALSE" Type="Note" DisplayName="Attached to" Required="FALSE" NumLines="6" Sortable="FALSE" ID="{36cc12a9-811f-4348-9494-45fdb6c561a2}" Version="12" StaticName="Attached_x0020_to" SourceID="{70650B4E-B343-42B9-AF4E-7BE6245FCC4B}" ColName="ntext2" RowOrdinal="0" RichText="FALSE" AllowHyperlink="TRUE" RichTextMode="Compatible" IsolateStyles="FALSE" AppendOnly="FALSE" UnlimitedLengthInDocumentLibrary="FALSE" />

Seems fine by me.

The field was a standard “Multiple lines of text” field, in a standard Document Library. It didn’t have Multiple Content Types enabled or anything or anything fancy was used. No JavaScript on the Edit Form was causing this nor was the Edit Form tampered with in SharePoint Designer 2007.

I tried switching the required field on and off through UI and code, but to no avail.

SPList list = web.GetList(listUrl);
SPField field = list.Fields["Attached to"];
field.Required = false;
field.Update();

So I decided to duplicate the problematic field in code, to see if any combination of properties was causing this; no luck.

SPList list = web.GetList(listUrl);
list.Fields.AddFieldAsXml("<Field Name='Attached_x0020_to2' FromBaseType='FALSE' Type='Note' DisplayName='Attached to2' Required='FALSE' NumLines='6' Sortable='FALSE' RichText='FALSE' AllowHyperlink='TRUE' RichTextMode='Compatible' IsolateStyles='FALSE' AppendOnly='FALSE' UnlimitedLengthInDocumentLibrary='FALSE' />");

Deleting the field and recreating it fixed the issue, but I didn’t want to go there because there were a lot of documents with version history already using the field.

Switching Multiple Content Types on and off didn’t seem to do much. When enabled my field wasn’t used by the default Document Content Type. This was awkward because it should have. Investigating further on this showed that SharePoint Manager 2007 did link the Content Type and Field together, and that the FieldRef was set as “Required”.

<ContentType ID="0x01010086B95C49F7836843AA3DB545631D2E1F" Name="Document" Group="Document Content Types" Description="Create a new document." V2ListTemplateName="doclib" Version="2" FeatureId="{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}"><FieldRefs><FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType"/><FieldRef ID="{5f47e085-2150-41dc-b661-442f3027f552}" Name="SelectFilename"/><FieldRef ID="{8553196d-ec8d-4564-9861-3dbe931050c8}" Name="FileLeafRef" Required="TRUE"/><FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}" Name="Created" Hidden="TRUE"/><FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" ShowInNewForm="FALSE" DisplayName="Title"/><FieldRef ID="{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}" Name="Modified" Hidden="TRUE"/><FieldRef ID="{822c78e3-1ea9-4943-b449-57863ad33ca9}" Name="Modified_x0020_By" Hidden="FALSE"/><FieldRef ID="{4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb}" Name="Created_x0020_By" Hidden="FALSE"/><FieldRef ID="{FEA60BF0-3AA4-4C00-B57F-1D1D6225BBDB}" Name="Attached_x0020_to" Required="TRUE" /></FieldRefs><XmlDocuments><XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"><FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"><Display>DocumentLibraryForm</Display>
<Edit>DocumentLibraryForm</Edit><New>DocumentLibraryForm</New></FormTemplates></XmlDocument>
</XmlDocuments><Folder TargetName="Forms/Document"/></ContentType><ContentTypeRef ID="0x012000ED1A3C38259C2A4DB6B76D64F7E6B13C"/><ContentType ID="0x0101"/><ContentType ID="0x0120"/>

So there was my issue and I could start working on a fix. No configuration or coding seemed to work however. I tried export and import using Chris O’Brien’s Content Deployment Wizard. My plan was to export the individual files, recreate the bugged field manually and then import again, hoping the metadata would be mapped correctly. But that didn’t work.

In the end I was so desperate I turned to modifying the record in the Content Database directly, something that’s totally unsupported and shouldn’t be done. If you do, thread careful, or better yet, don’t thread there at all…

UPDATE AllLists
SET tp_ContentTypes = '<ContentType ID="0x01010086B95C49F7836843AA3DB545631D2E1F" Name="Document" Group="Document Content Types" Description="Create a new document." V2ListTemplateName="doclib" Version="2" FeatureId="{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}"><FieldRefs><FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType"/><FieldRef ID="{5f47e085-2150-41dc-b661-442f3027f552}" Name="SelectFilename"/><FieldRef ID="{8553196d-ec8d-4564-9861-3dbe931050c8}" Name="FileLeafRef" Required="TRUE"/><FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}" Name="Created" Hidden="TRUE"/><FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" ShowInNewForm="FALSE" DisplayName="Title"/><FieldRef ID="{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}" Name="Modified" Hidden="TRUE"/><FieldRef ID="{822c78e3-1ea9-4943-b449-57863ad33ca9}" Name="Modified_x0020_By" Hidden="FALSE"/><FieldRef ID="{4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb}" Name="Created_x0020_By" Hidden="FALSE"/><FieldRef ID="{FEA60BF0-3AA4-4C00-B57F-1D1D6225BBDB}" Name="Attached_x0020_to" /></FieldRefs><XmlDocuments><XmlDocument NamespaceURI="
http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"><FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"><Display>DocumentLibraryForm</Display>
<Edit>DocumentLibraryForm</Edit><New>DocumentLibraryForm</New></FormTemplates></XmlDocument>
</XmlDocuments><Folder TargetName="Forms/Document"/></ContentType><ContentTypeRef ID="0x012000ED1A3C38259C2A4DB6B76D64F7E6B13C"/><ContentType ID="0x0101"/><ContentType ID="0x0120"/>'
WHERE tp_ID = '70650B4E-B343-42B9-AF4E-7BE6245FCC4B'

Probably with more time it would have worked with a combination of Import/Export and some coding.

Problem was solved, but can’t help feeling a bit dirty…

 


Links to this post

Comments

CAPTCHA Image Validation