Wednesday, October 29, 2014

Changes in Term values not getting reflected in Sites - Taxonomy Update Scheduler Job

Issue: I had a list containing some managed metadata columns bound to the respective term sets. I populated some items in the list. Then I went to the Term Store and modified a value of term that was used in one of the item. But when I went back to the list item, it was still showing the previous term only.
Reason: When doing any changes in the term store, there is a timer job called “Taxonomy Update Scheduler” that runs in background and synchronize the changes with the sites. So it will update the modified terms in the respective sites once it would run.  
Solution: You can check the status of this Taxonomy Update Scheduler timer job by following below steps:
·         Go to Central Administration.
·         Click on Monitoring on left navigation.
·         Then Under Timer Job Section, click on Check Job Status.
·         Then Under Timer Links heading on left navigation click on Scheduled Jobs.
·         On Top Right Side, under view selects Web Application and choose your web application.
·         You can find Taxonomy Update Scheduler Job from the list of specified jobs.
So there you can configure how frequently you want it to run according to your needs but generally it is configured to run every hour.
Once it runs, you can go back to the list item and check it would contain the modified term value.

Tuesday, October 28, 2014

Powershell script to create Managed Metadata Columns for each Term Set in a Term Store

I was writing a PowerShell script to create Managed Metadata columns in the library corresponding to each Term Set in the specified term store.
So below is the script with comments.

#This will load the SharePoint Snappin if not already loaded and also it will not throw any error if already loaded.
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}

    #define SPSite and SpWeb Object
    $spSite = Get-SPSite "http://sharepoint.com"
    $spWeb = $spSite.OpenWeb("")

    #Get Taxonomy Session
    $taxonomySession = Get-SPTaxonomySession -Site $spWeb.Site
    #Get TermStore
    $termStore = $taxonomySession.TermStores["Managed Metadata Service"]
    #Get Term group corresponding to which columns would be created in the target  list
    $group = $termStore.Groups["Term Group"]
    #Get Reference to List
    $targetList=$spWeb.Lists["Target List"]
    for($i=0;$i -lt $group.TermSets.Count;$i++){
    
     #Get Current TermSet    
     $termSet = $group.TermSets[$i]
    
     #Check if another column is already present in the list.
     if(!($targetList.Fields.ContainsField($termSet.Name)))
     {
         $taxonomyField = $targetList.Fields.CreateNewField("TaxonomyFieldType", $termSet.Name)

         #Gets or sets the GUID that identifies the TermStore object, which contains the Keywords for the site that the current TaxonomyField belongs to.
         $taxonomyField.SspId = $termSet.TermStore.Id

         #Gets or sets the GUID of the TermSet object that contains the Term objects used by the current TaxonomyField object.
         $taxonomyField.TermSetId = $termSet.Id

         #if true then user can select multiple terms
         $taxonomyField.AllowMultipleValues = $true

         #group in which this field will be saved
         $taxonomyField.Group = $fieldGroup
         $taxonomyField.StaticName = $termSet.Name
         $taxonomyField.ShowInEditForm = $true
         $taxonomyField.ShowInNewForm = $true
         $taxonomyField.Hidden = $false
         $taxonomyField.Required = $false
         $targetList.Fields.Add($taxonomyField);

        
     }
    }   
    $targetList.Update(); 
    $spWeb.Dispose()
    $spSite.Dispose()
   
    Write-host “Script Completed"           

Wednesday, October 1, 2014

Error while adding/updating Items

I was creating a PowerShell script to add files to Shared Documents library. Everything was going fine. I was able to add files to the library but suddenly I got the below error while running the script.





It says URL “Shared Documents/new.txt” is invalid. I was looking for error in script if I had done something wrong but it was the same script that was working fine a minute ago.  Error also says “It may refer to a nonexistent file or folder” but file and folder both exists.
I was able to upload document to library using PowerShell but in different web app. Now it was confirmed that Script is fine. So error was not with Script but with something else.
I tried to add and edit items in document manually by going to Shared Document Library and I got the below error. I was getting the error while doing any CRUD operations.












On doing some testing, I found that there was not enough space on database server which was causing the issue.
So the issue got resolved by cleaning up the database server.