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 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();
}
share|improve this question

1 Answer 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.

share|improve this answer
    
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. –  Tom Hill Dec 8 '11 at 14:47

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.