1

I have a "choice" (Checkboxes (allow multiple selections) ) column and wanted to convert the column as "managed metadata" column without any data loss. Suggest.

2 Answers 2

2

From my experience this will have to be done programmatically. Add a new managed metadata column manually then write a console app or PowerShell to loop trhough the items/documents and match the selected value with the managed metadata equivalent. Then do a SystemUpdate(false) on the item (the false part will preventing the version from being increased)

Hope this helps

1
  • Is there any script readily available? Commented Dec 20, 2012 at 5:38
0

Updating the managed metadata Field -> Multivalue (allow multivalue)

○ Create a local term group, set, terms, term
○ Ref - http://social.msdn.microsoft.com/Forums/hu/sharepointdevelopmentprevious/thread/75ae3a89-7d28-41d9-b58c-56d4f7e9771d

$site = Get-SPSite "SiteURL"
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$web = $site.openWeb() ;
$termStore = $session.TermStores["Enterprise Metadata Service Proxy"];
$group = $termStore.Groups["GroupName"];
$termSet = $group.TermSets["TermSet"];
$terms = $termSet.Terms;

$list = $web.Lists["ListName"];

$list.Items |% {

$spItem = $_;

write-host "Updating the Item - $($_.Id)";

#Get the taxonomy field for the list item
$taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$spItem.Fields["TaxField"]

#Create a term collection
$termCollection = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection($taxField);

$termName = $spItem["ChoiceField"].ToString() -replace ";#",",";

foreach($indTerm in $termName.Split(","))
{   
    if($indTerm.Length -gt 0)
    {
    #Get each individual term.
    $term = $terms | where {$_.Name -eq $indTerm}

    #Creating a field value that represents one term
    $taxonomyFieldValue = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue($taxField)
    $taxonomyFieldValue.TermGuid = $term.Id
    $taxonomyFieldValue.Label = $term.Name  

    #Add term to collection.
    $termCollection.Add($taxonomyFieldValue)
    }
}

#Adding the Term Collection to the column.  
$taxField.SetFieldValue($spItem, $termCollection);
$spItem.SystemUpdate();

}

$web.Close();
$site.Dispose();
1
  • I think you misinterpret the question. The OP wants to convert a SPChoiceField to a SPTaxonomyField, not change an existing TaxonomyField from simple to multiple valued
    – Steve B
    Commented Dec 20, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.