This has to be one of the weirdest things I’ve seen for ages – and there are a few weird things in SharePoint believe me.

I was trying to add a Custom Field to a Custom Content Type -I’ve done this many time before.  But no matter what I did I couldn’t get the Field to show.  Because the Custom Field was based upon a Custom Field Type, I naturally assumed the problem was mine and I had somehow missed out some bit of configuration.  But no, no problem of mine it turns out.  Here’s my XML code.

<xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Our own Site Field of our Custom Field Type -->
<Field ID="{8289B499-E2AE-48C2-80EA-8E9F52EB9542}"
Name="SessionRating"
StaticName="SessionRating"
DisplayName="Session Rating"
Group="NxtGenUG"
Type="NxtGenUG"
SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" />
<!-- Our Own Custom ContentType based on Event (0x02) which uses our 'SessionRating' Field -->
<ContentType ID="0x010200dc3e7098a5ab4ee6a7597e5177c2b56e"
Name="NxtGenUG Event"
Group="NxtGenUG"
Description="NxtGenUG Rated Session"
Inherits="TRUE"
Version="0">
<FieldRefs>
<!-- This is my Custom Field -->
<FieldRef ID="{8289B499-E2AE-48C2-80EA-8E9F52EB9542}" Name="SessionRating" DisplayName="Session Rating" Required="FALSE" />
</FieldRefs>
</ContentType>
</Elements>

Can you spot the problem? Nope neither could I.  For ages. There is in fact absolutely nothing wrong with the XML, apart from the XML comment above the <FieldRef> tag.  Yep.  Pretty unbelievable but removing the comment actually resolved the issue. WTF?!

I guess the chap or chapess who wrote that bit of XML parsing code was only looking for the next nodes after the node and not properly selecting all of the nodes. So don’t try to be good and comment your nodes, it will make your fields disappear. Doh!

Cheers

Dave Mc

One response

Leave a comment

The Blog

Dave Mc muses about history, travel, writing, coaching, astronomy, technology and life, family and the world around us. You may agree with his opinions, you may not, that’s life …