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'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

share|improve this question
add comment

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

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.