Taxonomy Rename Guide

Published by Mohit Agrawal on

We do get a lot of requests to update the terms in Taxonomy which are used across site collections of all the web applications connected to the same Managed Metadata Service. We have to make sure that these changes are reflecting across the farm. Here is the taxonomy rename guide which will help you to reflect these changes.

Renaming term in term store will not propagate the changes to site collections directly. To push these changes, SharePoint provides an OOTB timer job “Taxonomy Update Scheduler” which by default is scheduled to run every hour.

Initial Steps:

  • Go to term store -> term and rename the term
  • To reflect the changes immediately, Run “Taxonomy Update Scheduler” job.

If you check in the site collection now, the recent changes will be reflected.

Now what to do when timer job failed to sync the taxonomy. Below script will sync it for you.

 $siteURL = “http://sample.test.com”

 $site=Get-SPSite $siteURL

 [Microsoft.SharePoint.Taxonomy.TaxonomySession]::SyncHiddenList($site) 

 $site.dispose()

You can verify your changes in Site in Taxonomy Hidden List. Up to this point internal field value of item is not updated and it keeps taking the old taxonomy value. In multiple scenario due to this, your code will not run properly.

Steps to update internal field value of taxonomy column in Item:

  • Column contains Single Value

 using (SPSite site = new SPSite ("siteURL"))

 {

   SPWeb web = site.OpenWeb();

   SPList list = web.Lists.TryGetList("ListName");

   SPListItem listItem = list.GetItemById(1); // item ID

   listItem["TaxonomyColName"] = listItem["TaxonomyColName"] as TaxonomyFieldValue;

   listItem.Update();          

  }

 

  • Column contains Multiple Value

 using (SPSite site = new SPSite ("siteURL"))

    {

      SPWeb web = site.OpenWeb();

      SPList list = web.Lists.TryGetList("ListName");

      SPListItem listItem = list.GetItemById(1); // item ID

      listItem["TaxonomyColName"] = listItem["TaxonomyColName"] as TaxonomyFieldValueCollection;

      listItem.Update();             

     }

After executing script for items, internal field value will be updated and you can proceed further to your development.

 

 2,259 total views,  1 views today

Care to Share?

Mohit Agrawal

Experience in SharePoint developement, migration.

0 Comments

Leave a Reply