Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
SharePoint 2013 Custom Workflow Activity To Retrieve the Value of a Managed Metadata Column - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2015-03-19

Recently, I was asked to come up with a solution for retrieving the value of a Managed Metadata column for items in a SharePoint list. This solution was needed as part of a SharePoint Designer 2013 Workflow and, initially, I thought that it would be fairly simple to do by building a Custom Workflow Activity in Visual Studio 2013. As is often the case, it was more difficult than I expected and, therefore, I thought I would share my approach.

The challenge is that if we take the logical approach and use LookupListItem to query the list item in our custom action, the values that are returned for a Managed Metadata column in the JSON payload look something like this:

{\"__metadata\":{\"type\":\"SP.Taxonomy.TaxonomyFieldValue\"},\"Label\":\"1\",\"TermGuid\":\"c8111e66-f7b3-410e-a699-4e0b15e5de08\",\"WssId\":1}

As you can see, there are three parts to this value:

Label:"1"
TermGuid:"c8111e66-f7b3-410e-a699-4e0b15e5de08"
WssId:"1"

Unfortunately, none of these contain the actual text value we need for the selected term, which in this case is “Accounting”. 

Fortunately, the problem can be solved quite simply using the httpSend activity.

The first step is to create the necessary variables:

and arguments:

The next step is to add WebUri and GetCurrentlListId activities to populate the currentSiteUrl and currentListId variables, respectively.

We will be accessing the SharePoint 2013 REST endpoints in our httpSend request, so the actual Uri we will be using will need to look like this:

{Site Url}/_api/Web/Lists(guid'{List Guid}')/Items({Item Id})/{Field Name}

Consequently, we now need to add an Assign activity and set the httpUri variable to the following value:

String.Format("{0}/_api/Web/Lists(guid'{1}')/items({2})/{3}/Label", currentSiteUrl, currentListId, currentItemId.ToString(), mmFieldName)

Now, we add the httpSend activity and set the properties as follows:


If all goes as planned, the value of the serviceResponse should look something like this:

{"d":{"Label":"Accounting"}}

The final step is to parse out the value of the Label property, which is done by adding a GetDynamicValueProperty<T> activity and setting the Type to “String”.

The magic is done by setting the PropertyName value to “d/Label”, which extracts the value of the Label property as a string.

When the new custom activity is added to a SharePoint Designer Workflow, a String variable can be assigned to the mmFieldValue parameter, which will contain the value of the Managed Metadata column.

(Visited 189 times, 1 visits today)

About the author 

Rob Aycock

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.