I have yet to find a clear answer to this topic, so I'm writting this question in hope that someone can explain me the correct way to archieve my goal. I must also add that all my test was done on SharePoint 2007, but as far as I know the behaviour should be the same when using the 2010 version.
Premise: I wastrying to build a custom choice field that supports localization. Since the choice labels will change based on the current locale (let's forget SP 2010 multilanguage for a moment and suppose that only one-language web site are used) I started to search a way to implement locale-indipendent values for my custom field, something like the classical "id-value" concept used by traditional ASP choice controls.
I found on this page (also linked here) references to a <MAPPINGS> tag defined by the Field CAML element schema. The page states that the tag "Contains mappings of values to the choices displayed within a Choice field."
As a reference here is the sample field definition taken from the linked page:
<Field ID="{c15b34c3-ce7d-490a-b133-3f4de8801b76}" Type="Choice" Name="Status" DisplayName="$Resources:core,Tasks_Status;" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Status"> <CHOICES> <CHOICE>$Resources:core,Tasks_NotStarted;</CHOICE> <CHOICE>$Resources:core,Tasks_InProgress;</CHOICE> <CHOICE>$Resources:core,Tasks_Completed;</CHOICE> <CHOICE>$Resources:core,Tasks_Deferred;</CHOICE> <CHOICE>$Resources:core,Tasks_Waiting;</CHOICE> </CHOICES> <MAPPINGS> <MAPPING Value="1">$Resources:core,Tasks_NotStarted;</MAPPING> <MAPPING Value="2">$Resources:core,Tasks_InProgress;</MAPPING> <MAPPING Value="3">$Resources:core,Tasks_Completed;</MAPPING> <MAPPING Value="4">$Resources:core,Tasks_Deferred;</MAPPING> <MAPPING Value="5">$Resources:core,Tasks_Waiting;</MAPPING> </MAPPINGS> <Default>$Resources:core,Tasks_NotStarted;</Default> As you can see the sample defines five choices that will be localized, then procedes to map them to the values from 1 to 5.
The problem is that I had never been able to read the mapped value from custom code -no one of the field read method would return the expected value. It would seems that all mapping defined by the CAML field definition are simply ignored.
Some sources states that the tag has no real effect on the developer side (and only affect the valued stored by SharePoint in the content database), others indicates it as a form of feng-shui that can be used to enanche the cosmic energy flows in your feature files, but no one seems to have a concrete answer.
Anyone know what this tag should be used for?
PS: I also thinked of using the SPFieldMultiChoice.Mappings Property and build an extension method to implement some logic that would decode the field choice "text" to the mapped value (I should be able to to that, the property contains the full xml mapping node taken from the field definition), but before I try this solution I would like to know if I have missunderstood the tag usage.
EDIT: I have conducted some more research on the topic. While I didn't found any concrete answer (seems that someone is asking the same question on msdn without much luck...) I am starting to belive that the tag could indeed be a sofisticate form of feng-shui.
Take a look to the OOB definition for the HealtRuleScope field:
<?xml version="1.0" encoding="utf-16"?> <Field ID="{E59F08C9-FA34-4f94-A00A-F6458B1D3C56}" Name="HealthRuleScope" DisplayName="Scope" Type="Choice" Description="..." Group="_Hidden" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" StaticName="HealthRuleScope" AllowDeletion="FALSE" Required="TRUE"> <CHOICES> <CHOICE>All Servers</CHOICE> <CHOICE>Any Server</CHOICE> </CHOICES> <MAPPINGS> <MAPPING Value="1">All Servers</MAPPING> <MAPPING Value="2">Any Server</MAPPING> </MAPPINGS> <Default>Any Server</Default> </Field> This definition was taken from the site column on the central administration web site, using the SharePoint Manager tool (you could do the same with a custom application, but no need to re-invent anything). As you see the MAPPING section is still present, as per the field.xml feature definition in the 14 folder.
If you look at the same field on the Healt Rule list you will see that the section is missing. That would seem that the mapping ISN'T propagated to the child field on the list instance. It could still be possible that the mapping info is read from the parent field when the SharePoint object model requires it, but as now I am starting to think that this feature is simply un-implemented...