Monday, January 9, 2012

Adding Metadata fields as View fields in Schema.xml does not capture values

Recently, I worked on creating a custom list definition from a custom content type. That was not a big deal with the awesome VS 2010. BUT, I faced an issue with one field (Enterprise Keywords) with capturing data selected in it.

I was using custom forms for the content type's Display, Edit and Delete forms. First I was thinking that I was doing something wrong with my custom forms. I changed the forms to default OOTB default list forms for that content type and deployed. But, even with the default forms also it was failing.

Then i found out if I remove the "Enterprise Keywords" column from the list fields (not the content type fields) and re-add the same, it was working fine.

After a long research, I found this blog (http://www.sharepointconfig.com/2011/03/the-complete-guide-to-provisioning-sharepoint-2010-managed-metadata-fields) which explained me about the list event receivers get added for capturing the Taxonomy Lookup fields.


After adding the above mentioned Item Event receivers based on the list template everything seemed to be working fine. Use the below elements.xml to add the above mentioned item event receivers.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="10002">
    <Receiver>
      <Name>TaxonomyItemSynchronousAddedEventReceiver</Name>
      <Type>ItemAdding</Type>
      <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
      <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
      <SequenceNumber>10000</SequenceNumber>
    </Receiver>
    <Receiver>
      <Name>TaxonomyItemUpdatingEventReceiver</Name>
      <Type>ItemUpdating</Type>
      <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, 
Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
      <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
      <SequenceNumber>10000</SequenceNumber>
    </Receiver>
  </Receivers>
</Elements>

Just make sure the "ListTemplateId" matches with the "Type" attribute defined in the List Template definition .

Happy coding.
Senthil S

No comments:

Post a Comment