3

I am currently working on a project which requires me to use Managed Metadata columns in a list. I have used list definitions for creating the list and created the managed metadata field in its schema.xml

Now the problem is that the client has some data in the list on his environment(Assuming that the Term Store is configured exactly the same on his and my environment) and I need to somehow migrate the data from that list to the list in my environment without migrating the content database(as explained in this link migrating-managed-metadata-term-sets-to-another-farm-on-another-domain

As the managed metadata columns are non editable in the datasheet view, is there any other way to achieve this, by either exporting the data from the customer's list in an excel and populating the same to the list on my environment, or any other workaround either through the object model or powershell?

Thanks in Advance

1
  • Managed metadata columns are editable in datasheet.
    – ukhardy
    Feb 12, 2014 at 14:44

2 Answers 2

2

I am assuming that you have same termset on both your environments and you just want to copy the data from one list to another. You can do this via powershell (Note: there might be a better way, but I felt this was quick way to get going).

Save the list as template. Download the stp file. Rename it with .cab extension. Unzip to find manifest.xml. Find the nodes <Data>...</Data> and copy the entire <Data>...</Data> to another new xml file.

Now using powershell, read from xml file and updating the target list, something like below. (Assuming the taxfield to have only have one value).

$site = Get-SPSite "http://site/"
$targetList = $site.RootWeb.Lists["targetlistname"]
$taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$targetList.Fields["taxfieldname"]

#taxnonomy objects
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termStore = $session.DefaultKeywordsTermStore
$termStoreGroup = $termStore.Groups["GroupName"]
$termSet = $termStoreGroup.TermSets["TermsetName"]

#Get Contents of the xml file
[xml]$manifest = Get-Content "manifest.xml"

$manifest.Rows.Row | ForEach-Object {
   $row = $_
   $taxfieldelement = $row.Field | Where-Object { $_.Name -eq "taxfieldname" }
   $titleFieldelement = $row.Field | Where-Object { $_.Name -eq "Title" }

   $taxfieldvalue =  $taxfieldelement.InnerText.Substring($taxfieldelement.InnerText.IndexOf('#') + 1)
   $titlevalue =  $titlevalue.InnerText
   $term = $termSet.Terms | Where-Object { $_.Name -eq $taxfieldvalue }

   #udpate target list
   $taxFieldValue = New-Object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue($taxField)
   $taxFieldValue.PopulateFromLabelGuidPair($term.Name + "|" + $term.get_Id().ToString())
   $item = $list.Items.Add()
   $item["Title"] = $titlevalue
   $item["taxfieldname"] = $taxfieldvalue
   $item.Update()
}
0

How about a tool like this one?

http://metadataexportsps.codeplex.com/

It should allow you to export the TermSets you need to a csv & then import them in your environment.

Your Answer

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

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