The new Managed MetaData Service App within SharePoint 2010 is great for creating taxonomy, folksonomy, and for allowing people to tags documents with values – aside from just a normal list look-up – or choice field.
But – I came up against a pretty nasty scenario (bug ?) when using a CAML query – and attempting to use one of the Managed Metadata values.
Case in point :
I have a termset for “Division”. This has termset values for “HR”, “IT”, “Finance”, “Research & Development” and “Purchasing”.
When I have a dataview webpart – I use a CAML statement like this (ie. WHERE Division = Finance) :
<Eq>
<FieldRef Name="Division" />
<Value Type="Text">Finance</Value>
</Eq>
This works perfectly – every single time – for “Finance”. And – the same for “HR” and “IT” and “Purchasing”.
BUT – when I need to use the value for “Research & Development” – I was striking a problem.
Hhhhmmmm – why is that ?!?
Aaaah – it has an ‘ampersand’ in the value – that’s cool – I’ll just use THIS :
<Eq>
<FieldRef Name="Division" />
<Value Type="Text">Research & Development</Value>
</Eq>
Now – THAT would normally work for any other field within SharePoint – Choice, Text, etc – right ?
Sadly – NO. Not for Managed MetaData.
For some strange reason – it’s not actually an “ampersand” – like you’d type with SHIFT+7 on the keyboard.
Instead – it’s a wierd unicode value – have a look here :
The value is actually :
Research & Development
Instead of :
Research & Development
Can you spot the difference ?? No – that’s not a strange font, it’s a different CHARACTER… (WTF !)
So – the way to use within a CAML query – is to refer to the exact character :
<Eq>
<FieldRef Name="Division" />
<Value Type="Text">Research & Development</Value>
</Eq>
Of course !! “Well, there’s your problem” – as the MythBusters would say !
UPDATE : Just realised that the above character is being encoded – dammit !
What you need to include is :
Research [#]65286 Development
** You will need to remove the square brackets (!)
Thanks Wikipedia for the assistance with that one.
Hopefully – YOU don’t have the same hair-pulling exercise that *I* had – and you can get your DVWP + CAML to sing & dance the way it should – using the termset values.
Further Discussion :
This is a essentially a “data related” issue – it’s a problem because of some of the actual ‘values’ I have in my Managed MetaData termset – rather than anything wrong with Managed Metadata itself.
The BIGGER question is – should I be using the “&” value at all ??
Maybe the termset value should be :
Research and Development
This is being discussed within my development & “business analyst” team – with the thinking that we should NOT use any punctuation – or XML’ish values – even if the SharePoint UI allows it.
** Just because you CAN – doesn’t mean you SHOULD.
Your thoughts on this !?? Leave a comment – I’d be interesting to know your views. Is it a bug perhaps !?