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:
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("");
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”.
http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">DocumentLibraryForm
DocumentLibraryFormDocumentLibraryForm
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 = 'http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">DocumentLibraryForm
DocumentLibraryFormDocumentLibraryForm
'
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…