Skip to content
  • Home
  • About

a journey into software best practices with maria grazia merlo

Project and Product Management, Agile, Business Insights

Taxonomy

How to Update a Managed Metadata Field using a SharePoint Designer 2013 Workflow

January 4, 2016January 5, 2016Maria Grazia Merlo22 Comments

In this post I’m going to show you how to bypass a limitation of SharePoint Designer 2013 workflows that prevents us from directly updating a managed metadata field.

The proposed solution works for both SharePoint 2013 On Premises and Online (Office 365) and uses only the SharePoint Designer 2013 built-in actions.

Scenario

We have a custom list item with a managed metadata (taxonomy) field in it. We need to update the taxonomy field using a SharePoint Designer 2013 workflow.

taxonomy1.png

Problem

When you try to update a managed metadata field through the “Update List Item” action a BadRequest error occurs with the following message:

An unexpected ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘StartObject’ node was expected.

taxonomy2

This happens because SharePoint is expecting a complex type. However, any value you supply through a built-in list action in SharePoint Designer gets wrapped in quote marks and treated as a string literal…

So, how to get around this limitation?

Solution

When you add a taxonomy field in SharePoint, you are really adding two fields:

  • The first one is the visible field you see and edit
  • The second one is a hidden note field which holds the values for its associated field as plain text

Let’s say you add a taxonomy field called “TaxonomyField”, SharePoint will automatically add a note field called “TaxonomyField_0”.

Here is the solution to all our problems:

If we update the hidden field “TaxonomyField _0” with a well formatted text value then its associated taxonomy field gets updated as well.

Great!

We can update a hidden field in a SharePoint Designer 2013 workflow only using REST with the “Call HTTP Web Service” action.

So, all we need to do now is to get the internal name of our hidden field and set its value with a REST call using the format

Term1Name|Term1Guid

For a multi value managed metadata field we need to separate the entries with a semicolon, like this:

Term1Name|Term1Guid;Term2Name|Term2Guid

Let’s see how to do this in more detail…

Steps

1. Get the hidden field internal name

Finding the internal (static) name of the hidden field can be done by using the SharePoint REST API via a browser using a URL like this

https://site/_api/web/lists/getbytitle('listtitle')/fields

In the example below the static name for our hidden field is “l4ea604b343942df935ba60a0e9dd7ad”.

taxonomy3

2. Get the term name and guid

In the Term Store Management Tool for your site (Site Settings > Site Administration > Term Store Management) find the term you want to use to update the taxonomy field and get its name and guid.

In the example below the name and guid of our term are respectively “Term1” and “6dfad373-fc10-4a84-b83f-efa262c18275”.

taxonomy4

3. Get the list item type

To get the list item type we need to use the SharePoint REST API via a browser again using a URL like this

https://site/_api/web/lists/getbytitle('listtitle')

Then we must get the value for the “d:ListItemEntityTypeFullName” element.

In the example below the list item type is “SP.Data.TaxonomyListListItem”.

taxonomy5

4. Create the headers dictionary

Now we have all the information we need to start working with our SharePoint Designer 2013 workflow.

First of all we must build a dictionary to store some headers, specifically the following ones:

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
Content-Length: <length of post body>
X-HTTP-Method: MERGE
If-Match: *

taxonomy6

5. Create the metadata dictionary

Next we need to create a dictionary to store our metadata.
This dictionary will only contain one entry for the list item type we’ve obtained previously:

type: SP.Data.TaxonomyListListItem

taxonomy7

6. Create the data dictionary

Next, we need one more dictionary that will contain our request data.

The dictionary must have an entry with key “__metadata” (note the double underscore before the “metadata” string) with its value set to the previously created metadata dictionary.

We also need to add another entry in the data dictionary with its key set to the internal name of our hidden field and its value having the format “TermName|TermGuid”.

 __metadata: <metadata dictionary>
l4ea604b343942df935ba60a0e9dd7ad: Term1|6dfad373-fc10-4a84-b83f-efa262c18275

taxonomy8

7. Call the SharePoint REST service

Finally, we are ready to call the SharePoint REST service to update our taxonomy field. To do this we need to insert the “Call HTTP Web Service” action in our workflow.

The action URL must be constructed dynamically to point to the current item like this

https://site/_api/web/lists/getbytitle('listtitle')/items(n)

taxonomy9

The action verb must be set to POST.

taxonomy10

Then we need to set the request headers to the headers dictionary and the request content to the data dictionary.

taxonomy11

Conclusion

This is how the complete workflow should look like:

taxonomy12

Now we can publish and run it. Once it is over we’ll have our taxonomy field correctly updated.

taxonomy13

References

Beau Cameron

Matthew Yarlett

Fabian Williams

Advertisement
Sharepoint 2013Managed Metadata, Office 365, REST, Sharepoint 2013, Sharepoint Designer 2013, SharePoint Online, SPD 2013, Taxonomy, Workflow

Enter your email address to follow this blog and receive notifications of new posts by email.

Recent Posts

  • From Business to Personal, the Internet of Things is shaping the future
  • 5 Language Tips to Get Rid of Ambiguity in your Requirements
  • How to Make Usage Analytics Work in SharePoint 2016

Top Posts

  • How to Update a Managed Metadata Field using a SharePoint Designer 2013 Workflow
  • How to Create a Folder in a SharePoint 2013 List Using a SharePoint Designer 2013 Workflow
  • How to Make Usage Analytics Work in SharePoint 2016

Categories

  • Business Analysis (3)
  • IoT (1)
  • Office 365 (1)
  • Planning (2)
  • Programming (1)
  • Sharepoint 2013 (10)
  • SharePoint 2016 (1)

Archives

  • September 2020 (1)
  • December 2019 (1)
  • January 2019 (1)
  • July 2016 (1)
  • May 2016 (2)
  • April 2016 (2)
  • March 2016 (1)
  • February 2016 (1)
  • January 2016 (3)
  • December 2015 (4)
  • November 2015 (1)
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • a journey into software best practices with maria grazia merlo
    • Already have a WordPress.com account? Log in now.
    • a journey into software best practices with maria grazia merlo
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...