1

I am attempting to add metadata columns to existing lists via a workflow. I can create the actual columns without a problem, and if there is only a single default term there is, again, no problem. However, when the user has specified multiple terms for the column, I cannot get all terms to become defaults. Only the last term is applied. The field is created as a TaxonomyField, with MultipleTerms enabled.

Here is what I am doing:

mdataValue = listItem["Business Units"].ToString();
string[] mdataTerms = new string[1];
if (mdataValue.Contains(';'))
{
  mdataTerms = mdataValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
else
{
  mdataTerms[0] = mdataValue;
}
fld = docList.Fields["Business Units"];
foreach (string s in mdataTerms)
{
  mDefaults = new MetadataDefaults(docList);
  mDefaults.SetFieldDefault(docList.RootFolder, fld.InternalName, "1033;#" + s);
  mDefaults.Update();
}

1 Answer 1

1

The reason why only the last term is applied, is because you are overwriting the previous one with your code.

To add multiple values the better approach is to first build the whole string with terms and update the integer (in your code 1033) on every term to want to add in the foreach loop (or make it a for loop to use the loop int value). Between the terms ';#' has to be the separator. After the whole string is completed call SetFieldDefault and Update outside the loop and use the string with all terms as last inputparameter.

1
  • Sorry, that did not work. The format of the final parameter (for single terms) is '1033;#<term><term Guid>' where the '1033' is the locId. when you concatenate multiple terms together, there appears to be no delimiter between the locid (1033) and the Guid prior to it. If you have some sample code I would appreciate looking at it - this is last little piece that needs to work before delivery. Commented Dec 8, 2011 at 14:47

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.