Tuesday, June 2, 2009

Always Capitalize (all-caps) Boolean Values in CAML

So here I was, late at night, banging my head against the desk trying to figure out why my a custom field’s custom property wasn’t hiding when I clearly stated Hidden=”true”.  As it turns out, you need to specify the uppercase value for that boolean or it simply won’t work.  There’s no error; it just doesn’t hide.  Here’s a snippet of code where this bit me while developing a custom column using the ProperySchema section to allow additional settings to be used for the field.

<FieldTypes>
<
FieldType>
<
Field Name="TypeName">CustomColumn</Field>
<
Field Name="ParentType">Note</Field>
<
Field Name="TypeDisplayName">My Custom Column</Field>
<
Field Name="TypeShortDescription">My Custom Column</Field>
<
Field Name="UserCreatable">TRUE</Field>
<
Field Name="ShowOnListCreate">TRUE</Field>
<
Field Name="ShowOnSurveyCreate">TRUE</Field>
<
Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
<
Field Name="ShowOnColumnTemplateCreate">FALSE</Field>
<
Field Name="FieldTypeClass">ACME.SharePoint.Blah.CustomField,
ACME.SharePoint.Columns, Version=1.0.0...</Field>
<PropertySchema>
<
Fields>
<
Field Name="MySetting"
Hidden="TRUE"
DisplayName="My Setting:"
MaxLength="500"
DisplaySize="40"
Type="Text">
<
Default></Default>
</
Field>
   ...

As you can see Hidden is set to “TRUE.”  “true” simply does not work.



What’s funny is that the WSS.XSD gives you intellisense in VS.NET (in most areas) for the following options for boolean fields: true, false, True, False, TRUE, FALSE.  Ok.  Why?


This was just one case where my choice of case caused an issue.  What about everywhere else?  So proceeded to tell my colleagues, including Bryan Phillips, about this oddity with hiding properties of custom fields.  He said that he always uses uppercase.  Not only for custom columns, but for everything.  I’ve typically used lowercase since it seemed to be close to my c# practices.  However, from now on, I’m going to capitalize my boolean values.

No comments:

Post a Comment