Jkiller295
Jkiller295
CC#
Created by Jkiller295 on 12/10/2024 in #help
I need help with SharePoint CSOM and Managed Metadata columns please
The issue is that the Taxonomy fields in the target library remain blank. I verified that the field settings match between the source and target libraries, and they reference the same TermSet. I also attempted to manually set the Term values in the target library, but they disappear after saving. Does anyone have any insight into why this might be happening? Any advice is greatly appreciated!
4 replies
CC#
Created by Jkiller295 on 12/10/2024 in #help
I need help with SharePoint CSOM and Managed Metadata columns please
To set the field values after copying files to the new library, I use this code:
Field targetField = targetLibrary.Fields.GetByInternalNameOrTitle(kvp.Key);
targetContext.Load(targetField);
targetContext.ExecuteQueryRetry();
if (fieldValue is TaxonomyFieldValueCollection termCollection)
{
TaxonomyField targetTaxonomyField = targetContext.CastTo<TaxonomyField>(targetField);
TaxonomyFieldValueCollection destinationTaxonomyValues = new TaxonomyFieldValueCollection(targetContext, null, targetTaxonomyField);
foreach (TaxonomyFieldValue value in termCollection)
{
destinationTaxonomyValues.PopulateFromLabelGuidPairs($"{value.Label}|{value.TermGuid}");
}
targetTaxonomyField.SetFieldValueByValueCollection(newListItem, destinationTaxonomyValues);
}
else if (fieldValue is TaxonomyFieldValue term)
{
TaxonomyField targetTaxonomyField = targetContext.CastTo<TaxonomyField>(targetField);
TaxonomyFieldValue termValue = new TaxonomyFieldValue
{
TermGuid = term.TermGuid
};
targetTaxonomyField.SetFieldValueByValue(newListItem, termValue);
}
Field targetField = targetLibrary.Fields.GetByInternalNameOrTitle(kvp.Key);
targetContext.Load(targetField);
targetContext.ExecuteQueryRetry();
if (fieldValue is TaxonomyFieldValueCollection termCollection)
{
TaxonomyField targetTaxonomyField = targetContext.CastTo<TaxonomyField>(targetField);
TaxonomyFieldValueCollection destinationTaxonomyValues = new TaxonomyFieldValueCollection(targetContext, null, targetTaxonomyField);
foreach (TaxonomyFieldValue value in termCollection)
{
destinationTaxonomyValues.PopulateFromLabelGuidPairs($"{value.Label}|{value.TermGuid}");
}
targetTaxonomyField.SetFieldValueByValueCollection(newListItem, destinationTaxonomyValues);
}
else if (fieldValue is TaxonomyFieldValue term)
{
TaxonomyField targetTaxonomyField = targetContext.CastTo<TaxonomyField>(targetField);
TaxonomyFieldValue termValue = new TaxonomyFieldValue
{
TermGuid = term.TermGuid
};
targetTaxonomyField.SetFieldValueByValue(newListItem, termValue);
}
4 replies
CC#
Created by Jkiller295 on 12/10/2024 in #help
I need help with SharePoint CSOM and Managed Metadata columns please
4 replies