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.
- Edited by darren1372 16 hours 31 minutes ago