Sync TaxonomyHiddenList after updating Term value programmatically for SharePoint 2013/2016

In one of my project, there was a requirement to manually update term set title and see the updated version in library view. When I did that it didn’t reflect the change on demand. So let me share my experience with the below scenario:

I have one library where I have added a custom field of type managed metadata type.

Columns

These fields (Regions, Survey Title) are targeting to its related TermSet from the Term Store and showing it on the library view.

When I added a new item to the library, I selected it’s metadata and saved the document.

Now I had change request to update metadata term’s title. Let’s consider Region has one value “Colorado” and change request was to change it to “CO”.

To achieve this, I first updated the term title in the term store manager but change wasn’t reflected immediately.

Below are the different ways to achieve the changes immediately:

Out of the Box way:

There is a Timer job for this, it actually sync the term store data to the hidden taxonomy list for that site collection and update wherever term fields are used.

Though to run this job manually, below are steps I followed:

  • Go to the Central Administration > Monitoring > Job DefinitionsTaxonomy Update Scheduler (for your web application). Open it.
  • By default that Job will run hourly, so to run it manually you have to click on Run Now.
  • Once Job is successful, Data from term store will be synced to the TaxonomyHiddenList for that site collection and I was able to see the updated metadata field title for the CO in place of Colorado.

Programmatically with PowerShell:

This could also be done by PowerShell, Below is the snippet I used:

$siteUrl = "http://mysharepoint:1327/"
$site = Get-SPSite $siteUrl
[Microsoft.SharePoint.Taxonomy.TaxonomySession]::SyncHiddenList($site)
$site.dispose()

Programatically with C# SharePoint Console Application:

Similar way you can achieve the same with Server side object model. Following code snippet by creating simple console application and run where SharePoint is installed. Below was the snippet I used:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using System;

namespace TaxonomyUpdater
{
    public static class TaxonomyHiddenList
    {
        public static void Update(string SiteUrl)
        {
            SPSite Site2Update = new SPSite(SiteUrl);
            TaxonomySession.SyncHiddenList(Site2Update);
            Site2Update.Dispose();
        }
    }
}

Additional Problem:

There was a situation where I wasn’t able to update the termset data by any of the above solution, from this blog post: Taxonomy Update Scheduler not working? I was able to figure out there was a table in the MMS database called ECMUsedTerm. This table wasn’t updated with all the terms data in it. This could be caused by two different scenarios:

  1. If we recreated the Managed Metadata Service with a clean database, importing the terms with the same id’s then of course the ECMUsedTerm table is empty / information is lost.
  2. If we moved the content database from one farm to another (maybe from staging to prod) which of course has a new Managed Metadata Service, then the ECMUsedTerm table is of course not in sync.

Solution:

To solve this issue, from the article referred I found the below PowerShell code, which will sync the ECMUsedTerm data.

$url = "https://yoursite"
$site = Get-SPSite $url
$tax = Get-SPTaxonomySession -Site $url
$ts = $tax.TermStores[0]
$ts.UpdateUsedTermsOnSite($site)
$site.dispose()

By using this snippet, I was able to update the records in the ECMUsedTerm table of MMS database and now my term set was reflecting once any of the above solution or timer job is ran successfully.

Happy SharePointing!!

Advertisements

Show All People in search result Webpart

In this blog post, I will explain how you can show all people by default when you load the page having search result webpart.

I assume in your publishing page you have added search result webpart. Now Edit webpart properties and click Change query

Search Result Webpart properties

Search Result Webpart properties

In Build Your Query dialog, select a query dropdown to Local People Results (System) and in Query text add following line:

contentclass:spspeople

Now click Test query.

Build Your Query Dialog

Build Your Query Dialog

Once you test the query, you will see the result in the right side Search Result Preview panel.

Search User Result Preview

Search User Result Preview

Now click OK and Save the page. You will now able to see all employee directory.

Happy SharePointing!!

SharePoint 2013 List Template IDs

Some important ListTemplateID for List for version SharePoint 2013:

  • 100 – Generic list
  • 101 – Document library
  • 102 – Survey
  • 103 – Links list
  • 104 – Announcements list
  • 105 – Contacts list
  • 106 – Events list
  • 107 – Tasks list
  • 108 – Discussion board
  • 109 – Picture library
  • 110 – Data sources
  • 111 – Site template gallery
  • 112 – User Information list
  • 113 – Web Part gallery
  • 114 – List template gallery
  • 115 – XML Form library
  • 116 – Master pages gallery
  • 117 – No-Code Workflows
  • 118 – Custom Workflow Process
  • 119 – Wiki Page library
  • 120 – Custom grid for a list
  • 130 – Data Connection library
  • 140 – Workflow History
  • 150 – Gantt Tasks list
  • 200 – Meeting Series list
  • 201 – Meeting Agenda list
  • 202 – Meeting Attendees list
  • 204 – Meeting Decisions list
  • 207 – Meeting Objectives list
  • 210 – Meeting text box
  • 211 – Meeting Things To Bring list
  • 212 – Meeting Workspace Pages list
  • 300 – Portal Sites list
  • 301 – Blog Posts list
  • 302 – Blog Comments list
  • 303 – Blog Categories list
  • 1100 – Issue tracking
  • 1200 – Administrator tasks list
  • 2002 – Personal document library
  • 2003 – Private document library

Group & Sort by Month in List View Trick

Group by month is very simple task to achieve in SharePoint List View.
Simply create one computed column with formula:

=TEXT([Start Time],"mmmm")

Now Group by that view by this field to view in particular order ascending or descending.

SiteColumnView
As shown above, it will only order item by alphabetically for month keyword, but it will not order as per the month ordering.

So to achieve that add following formula:
=REPT(" ",13-MONTH([Start Time]))&TEXT([Start Time],"mmmm")

SortByMonth

What’s the trick? To force the order, we are adding a bunch of white spaces before the month name. The calculated Month actually contains the following values (each _ represents a white space):
____________January
___________February
__________March

__November
_December

Now, why don’t we see these spaces on the Web page? What makes the magic work is that when you insert multiple spaces in a Web page, the html specification says that

user agents should collapse input white space sequences

That’s it!

Set an Email alert for Document library or List for SharePoint 2013

In this post, I will explain how to add an alert on document library or list to get notified about item added, updated or deleted. Steps to follow for adding an alert:

1. First of all Open List or Library.
2. If it is library then open Documents, or it is List then open Lists ribbon tab. In my example I have taken Document Library.

LibraryTab
3. Now under Share & Track section, search Alert Me option. Click on Set alert on this library

Set Alert Link

4. A dialog box will appear with available options like Alert Title, Send Alerts To, Delivery Method, Change Type, Send Alerts for These Changes, When to Send Alerts.

Alert Dialog Options

5. Apply relevant configuration on dialog and then click OK. And you are done with setting alert.