Powershell /or other method to populate Hidden Taxonomy List with unused Terms

Hi all,
I am currently looking for a method to populate the Hidden Taxonomy list with all the terms in my terms store. The resaon being we have a list that populates from an external source, then based on the vaue (Title) we look in the hidden taxonomy list to get the guid, in order to set the taxonomy field when we create an item in the destination list (from metadata in the source/external list). However, terms only get popluated in the hidden taxonomy list when a term has been used. This is no good as if an item has a term /value that we need to use for the first time we cannot use the hidden taxonomy list to reg it's GUID as it will not be there. I tried to use the below powershell but got an error. My term store application is called "Managed Metadata Service - Global Terms"
and I have one group called underwriting that has several terms sets and terms within it. I want all the terms in the term sets under the group underwriting to be pulled into the hidden taxonomy list.

I have set the paramters in the script as below but getting the error

"Cannot index into a null array
$newItem[path] =$parent
and this error:
Exception calling "GetString" with "1" argumeny(s) Array cannot be null
Paramter name bytes"
$newItem[Term1033"]=
$term.NAme.Replace(System.text.Encoding]::UTF8.G...


$url = "http://mysitecollectionurl/bla/bla"
$termSet=Get-SPTaxonomySession -Site $url
$termStore=$termSet.TermStores["Managed Metadata Service - Global Terms"]

$termGroup=$termStore.Groups["Underwriting"]

$termStoreId = $termGroup.Id

$listTaxo = $web.Lists["TaxonomyHiddenList"]


foreach ($termGroups in $termGroup.TermSets)
{
$termSetId = $termGroups.Id
foreach ($term in $termGroups.GetAllTerms())
{
#getNode $termSets
$i = 0
$parent = ""
$termParent = $term.Parent
while($i -le 6)
{

if($termParent.Id -ne $null)
{
$parent += $termParent.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&")+":"
}
else
{
break
}
$termParent = $termParent.Parent
$i++
}
$test = $parent.split(",")
[array]::Reverse($test)
$parent = $test -join ','

$parent += $term.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&")

$newItem = $listTaxo.Items.Add()
$newItem["Title"] = $term.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&")
$newItem["IdForTermStore"] = $termStoreId
$newItem["IdForTerm"] = $term.id
$newItem["IdForTermSet"] = $termSetId
$newItem["Term"] = $term.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&")
$newItem["Path"] = $parent
$newItem["Term1033"] = $term.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&")
$newItem["Path1033"] = $parent

#Update the object so it gets saved to the list
$newItem.Update()


}
}



Any help appreciated.


July 17th, 2015 10:24am

Hi Darren,

Hope it helps

http://splog.cairo.ag/2012/09/20/updating-the-hidden-taxonomy-list-via-sharepoint-management-shell-2010/

Free Windows Admin Tool Kit Click here and download it now
July 17th, 2015 10:44am

Hi Lakshmanan,

thank you for your reply, however the script in the article only sync's the used terms. It doesn't pull in unused terms in the hidden list. I need a way to pull in all the terms into the list that are not being currently used in items in the site collection.

July 17th, 2015 11:21am

hello

may be it worth to look at the problem from other side:

- you wrote that "based on the vaue (Title) we look in the hidden taxonomy list to get the guid". What if instead of hidden taxonomy list you will look directly in term store, find label there by title and return its id?

- creative solution: create new list with managed metadata field with multi selection bound to appropriate term set, create new list item in this list, create custom timer job which will run e.g. each 5 minutes, will get all terms currently available and update list item with all these terms. In this case all terms will be always used (with possible 5 minutes delay) and will be added to hidden taxonomy list automatically.

Free Windows Admin Tool Kit Click here and download it now
July 17th, 2015 11:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics