none
Mapping a Site Column Field to Term Store Term Set RRS feed

  • Question

  • Please note that this is for SharePoint Online and not for SharePoint 2013. My code is fine till the last line, however, I'm not sure how to map the site column (created before this code)  field to the Term Set. In this case Document Classification. All I can find are examples on SharePoint 2013 which is using $field.SspId. This is invalid in SharePoint Online. Please suggest.

                $context = New-Object Microsoft.SharePoint.Client.ClientContext($Site.Url)
                $context.Credentials = $SPOCredentials
                $web = $Site.RootWeb
                $context.ExecuteQuery()

                
                $taxStore = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($context)  
                $context.Load($taxStore)  
                $context.ExecuteQuery()

                $TermStores = $taxStore.TermStores 
                $context.Load($TermStores)  
                $context.ExecuteQuery()

                #Bind to Term Store
                $TermStore = $TermStores[0]
                $context.Load($TermStore)
                $context.ExecuteQuery()   

                #Bind to Group
                $Group = $TermStore.Groups.GetByName("MyTermSets")
                $context.Load($Group)
                $context.ExecuteQuery() 

                $Termset = $Group.TermSets.GetByName("Document Classification")
                $context.Load($Termset)
                $context.ExecuteQuery()


    SharePoint Architect

    Saturday, February 25, 2017 6:03 PM

Answers

  • Resolved the issue. Here's the remaining code:

    $column = $fields.GetByInternalNameOrTitle("Document Classification") 
                $txField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($context, $column)
                $txField.SspId = $TermStore.Id
                $txField.TermSetId = $Termset.Id
                $txField.Update() 
                $context.ExecuteQuery()   


    SharePoint Architect

    Saturday, February 25, 2017 7:40 PM

All replies

  • Resolved the issue. Here's the remaining code:

    $column = $fields.GetByInternalNameOrTitle("Document Classification") 
                $txField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($context, $column)
                $txField.SspId = $TermStore.Id
                $txField.TermSetId = $Termset.Id
                $txField.Update() 
                $context.ExecuteQuery()   


    SharePoint Architect

    Saturday, February 25, 2017 7:40 PM
  • Hi Debasish,

    Glad to hear that you solve this issue, thanks for your sharing.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, February 27, 2017 9:29 AM
    Moderator