Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have two lists that are using the same Managed Metadata column. I am attempting to copy this column when I create a new entry in one of the lists. My code looks like this:

        SPListItem li = site.RootWeb.Lists["UploadList"].AddItem();
        li["Title"] = workflowProperties.Item["Title"];
        li["TaxKeyword"] = (TaxonomyFieldValueCollection)workflowProperties.Item["TaxKeyword"]; 
        li.Update();

For some reason when I look at the new list item that is created it never has a value for the "TaxKeyword" column. I have tried not casting it to TaxonomyFieldValueCollection and it still does not work... Any suggestions on how to do this?

share|improve this question
add comment

2 Answers 2

When setting the value of Taxonomy Fields always use TaxonomyField.SetFieldValue

var sourceValue = sourceItem["SColumn"] as TaxonomyFieldValueCollection; 
var targetField = targetList.Fields["TColumn"] as TaxonomyField; 
targetField.SetFieldValue(targetItem, sourceValue);
targetItem.Update(); 

Just setting targetItem["field"] doesn't update the hidden notes field or the hidden lookuplist

share|improve this answer
add comment

Use PopulateFromGuidValuePair method. Below is a snippet to set Managed Column value from another one.

TaxonomyFieldValueCollection sourceTaxVal = sourceItem["MMColumn"] as TaxonomyFieldValueCollection;
string taxVal = string.Empty;
foreach (TaxonomyFieldValue val in sourceTaxVal)
 {
    taxVal += val.Label + "|" + val.TermGuid + ";";
 }
 //taxVal = sourceItem["MMColumn"].ToString() //will also result in same value as above
 TaxonomyFieldValueCollection targetTaxVal = new TaxonomyFieldValueCollection(targetList.Fields["MMColumn"]);
 targetTaxVal.PopulateFromLabelGuidPairs(taxVal);
 targetItem["MMColumn"] = targetTaxVal;
 targetItem.Update();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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