The specific error message you get is: Error – Failed to get value of the “” column from the “Managed Metadata” field type control. text) field that is required for the metadata column to work.The first taxonomy field we created actually only stores a lookup value to a list within the current site collection and it is the note field that actually stores the names and Id’s of each selected term.
With this information we can use the following steps to deploy managed metadata fields that avoid these issues.I’ve also added in some additional error handling so we get informative messages if the metadata service and/or term set does not exist.Note that if we are only creating a site column (or even a content type) this should work without completing the following steps.If we inspect a list that contains a managed metadata field created through the UI it shows two event receivers.These are the Taxonomy Item Synchronous Added Event Receiver for the Item Adding event and the Taxonomy Item Updating Event Receiver for the Item Updating event.I’ve based the code on Wictor’s excellent example with a couple of minor updates.
Instead of hardcoding the name of the term store I’m getting the default keyword store associated with the site (this means we do not have to hardcode the name of the managed metadata service but you should check this works in all your environments).
This is another step that isn’t always mentioned but if this feature is not present then you are presented with a greyed out metadata selection when adding or editing items (note this also happens if the field is not connected to a term set).
You won’t get any obvious error messages and the feature is hidden so you won’t see it in the site features list either.
To add these to our custom list definition we use an element file similar to the one below (note the List Template Id should match the Type attribute of our list definition).
As a final step we can optionally create a list instance so that when we deploy our solution lists are created automatically.
At this point we have a robust way of deploying a standalone site column which is useful in certain situations but in many situations we need to provision content types, list definitions and list instances which is when things get tricky…