Wednesday, January 11, 2012

Deep dive and workaround to resolve renamed Managed Metadata value not applied to list items issue

After upgraded to SharePoint 2010 in August 2010, we have started utilize managed metadata services to many sites. However, we identified many issues related the services. One of the issues is the list managedmetadata value NOT updated after managed metadata term store value changed. You could use site collection local term store to reproduce this easily if you have the issue. This was confirmed with other customers from different blogs. From Microsoft release notes, SP1 and June CU suppose to fix this issue. However after we applied the SP1 and June CU in August 2011, we still have this issue on productions. The strange behaviors is we are not able to reproduce the issue on all other non production environments including DEV, TEST, STAGE, and development boxes.  This is the reason I have to pick up this issue and would like to share the finding and workaround for this issue.

First let’s understand the managed metadata field - Taxonomy Fields. They are lookup columns as Wictor explained in his blog. Three types of data play critical role to synchronize taxonomy value with managed metadata term store. These three data types are listed below and the relationship is explained in my previous blog.
  • Taxonomy Fields on your list
  • TaxonomyHiddenList on your site
  • Managed metadata term store tables from service application
There are several processes that will participate the pushes changes from the Term store into TaxonomyHiddenList so the list will look up to the changed value. You got the key point and here are the processes involve and their functions.
  • Taxonomy Update Scheduler - OTB Sharepoint timer job which synchronizes changes from Term store into Sharepoint web site. This timer jobs pushes changes from the Term store into your list.
  • ItemUpdating and ItemUpdated events – These events on your hidden list TaxonomyHiddenList will update the lookup values on your list
  •  TaxonomyFieldAdded site collection feature - Responsible for creating the hidden list TaxonomyHiddenList as well as adding the item receivers
  •  TaxonomyItemSynchronousAddedEventReceiver and TaxonomyItemUpdatingEventReceiver events– These event receivers are added to your list for  taxonomy changeson your list events
Second let’s summarize the process the process so we could understand how SharePoint update the list Taxonomy Fields.
  • When Taxonomy Fields added to a list, TaxonomyFieldAdded site collection feature is activated to creates hidden list TaxonomyHiddenList as well as ItemUpdating and ItemUpdated events to the hidden list
  • If managed metadata term store term changes, Taxonomy Update Scheduler will pick the changes and update the TaxonomyHiddenList. This update will then trigger the ItemUpdating and ItemUpdated events on hidden list TaxonomyHiddenList to update the lookup values on your list
  • The lookup Taxonomy Field value of your list changes will trigger TaxonomyItemSynchronousAddedEventReceiver/TaxonomyItemUpdatingEventReceiver events of the list. You could write event receiver to track the call sequence. You may find yourself to have gun using API.
Now we understand all the data and processes involved to synchronize taxonomy value with managed metadata term store, we track what is missing after deploy the event receivers to track the sequence calls. In the SharePoint farm that Managed Metadata value not applied to list items, the ItemUpdating and ItemUpdated events on hidden list TaxonomyHiddenList never triggered!!!

Well you might have the workaround in your mind - if we verify related feature, event receiver, and dcheduled timer job listed above are working, we could update the TaxonomyHiddenListhiden list to reflect the term stor change to trigger event receiver and update the list lookup values!

Here are the steps ypou could refer. My site in the example is http://sbx08/sites/Harry  that has List1 with one Taxonomy Field named MM.
  1. Verify Taxonomy Update Scheduler is scheduled on the webapp and run successfully as in the screenshot. You may need to change the frequency of the timer job if there is issue here.

     2.  Verify whether you have TaxonomyFieldAdded site collection feature enabled on the site. Use               command from Glyn Clough's Blog. You many need to enable the feature is it’s not enabled already.

      Get-SPFeature -Site http://sbx08/sites/Harry | Sort DisplayName | FT DisplayName,Id

           Result is:
           TaxonomyFieldAdded  73ef14b1-13a9-416b-a9b5-ececa2b0604c

    3. Verify whether you have event receivers added correctly to your lists with Taxonomy Fields. You could use the powershell provided by Mike Smith. I never find issue that these event receivers are missing but you should try to activate the TaxonomyFieldAdded site collection feature to add them if they are missing.

        $site = New-Object Microsoft.SharePoint.SPSite("http://sbx08/sites/Harry")
        $web = $site.Rootweb
        $web.Lists | Where {$_.eventreceivers.count -gt 0} | Select title,eventreceivers

        Result is:
        Title          : List1
        EventReceivers : {TaxonomyItemSynchronousAddedEventReceiver,    

At last, if you have changed all those listed above and you are still out of luck, you could use powershell provided Joerg Sinemus to update the TaxonomyHiddenList of the site you have Taxonomy Fields on your list. Here is the code snippet.

SPSite Site2Update = new SPSite(SiteUrl);
It works good for the one of our production list and we are converting the code to C# and deploy as customized timer job. The real issue is how we get the list of the site collections with Taxonomy Fields quickly with minutes so we could schedule the customized timer job within 15 minutes. Here are different ways I'm thinking to identify the site collections that are using managed metadata Taxonomy Fields.

  1. Check any site collection has site collection feature TaxonomyFieldAdded enabled
  2. Check any site collection has hidden list TaxonomyHiddenList 
  3. Query managed metadata tables
 We will compare which one is the fastest way and then update the hidden list.

Hope this could help.

1 comment:

  1. Thank you for this article. I hope this will provide our computer department enough information on how to resolve this issue. :-)