2

I'm working on a SharePoint 2013 publishing approval workflow that needs to compare if a managed metadata field in a newly created item is set to a specific value. This in order to assign a task to a sharepoint group if the condition is true. I'm having difficulties in finding the value of the MMD field. I've tried to do it in the Term|GUID-way(Term|xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). But I don't get any values at all.

If anyone has some pointers or advice on this issue, it would be great!

Thanks, Joakim

1 Answer 1

1

Here is a snippet that I have used to set the values in a TaxonomyField in SharePoint 2010.

However the object model hasn't changed too much in this area:-

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomyfieldvalue_members.aspx

This code is expecting an SPListItem object to be passed through.

string labelValue = String.Empty;
TaxonomyField field = item.Fields.GetField(fieldName) as TaxonomyField;
string fieldValue = item[field.Id].ToString();

TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(field);
string fieldValue = item[field.Id].ToString();
if (fieldValue.Contains("|"))
{
  taxonomyFieldValue.PopulateFromLabelGuidPair(fieldValue);
}

labelValue = taxonomyFieldValue.Label;

You can now compare the value inside labelValue with the value you need to check.

Your Answer

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

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