Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

How to update SharePoint managed metadata column (Power Automate)

Posted on October 27, 2021October 31, 2021 by Tom

“What if you want to update the SharePoint managed metadata column with Power Automate? I have a Content Type and it has a managed metadata site column.”


The managed metadata SharePoint column is probably the most complicated one to update. You can’t just take the term name and update it. You must use the term id in the update action. An id that has a similar format as the Microsoft 365 group id, but is a bit harder to get. The reason is that you don’t need just the term id, you need id of the term group and term set too. Without them you can’t get the term id that’s necessary for the update.

Get the term group and term set id

Since the managed metadata column forces you to select the source term set, this id collection is a one time task. You need to extract the id’s only once and then reuse them in the flow.

Term group id

For this id collection you can build a separate flow, which you can delete after you get the id’s. Start from the manual trigger, and add the ‘Send an HTTP request to SharePoint’ action. You’ll use it to get the first id, the term group id.

Method: GET

Uri: _api/v2.1/termStore/groups?$filter=name eq '<term group name>'

Note: < … > is a placeholder, replace it including the < and >.

Run the flow and check the run history. In the http action result will be a single term group, including its id.

Power Automate update managed metadata SharePoint

Term set id

Now, when you’ve got the term group id, you can use it to get the term set id. Add another ‘Send an HTTP request to SharePoint’ action in that flow. In this request you’ll extract all term sets within the group.

Method: GET

Uri: _api/v2.1/termStore/groups/<term group id>/sets

Note: < … > is a placeholder, replace it including the < and >.

Again, run the flow. The result of this second http request will be a list of all sets in that group, including their details. Among them their id’s. Search for the desired term set by the name, and take the id.

Power Automate update managed metadata SharePoint

That’s the end of the id gathering flow, it served it’s purpose. Now, when you’ve got the two id’s, you can go back to updating the managed metadata column.

Get the term id

Knowing the id’s allows you to finally search for the last id, the id of the term itself. That means another ‘Send an HTTP request to SharePoint’ action to list all available terms.

Method: GET

Uri: _api/v2.1/termStore/groups/<term group id>/sets/<term set id>/terms

Note: < … > are placeholders, replace them including the < and >.

Since it’ll return all terms, but you want to get only a specific one (the one to update), you should filter it out. Take only the one with the desired name in the ‘labels’ array using the ‘Filter array’ action.

Power Automate update managed metadata SharePoint

For example, let’s extract the term called ‘Term1’. As it’s an array inside the array of all terms, the easiest way is to convert the labels into a string, and search if it contains the term name. Take only the ‘value’ from the http request output, e.g.:

outputs('Send_an_HTTP_request_to_SharePoint_3')?['body']?['value']

… and search for the ‘labels’ converted to string.

string(item()?['labels'])

Note: the action name inside outputs() must correspond to your http request action name.

The result will be a single term, including the term id.

Update the managed metadata column

With the term id, and the term name, you can finally update the column. Use the same HTTP request that was already described multiple times.

Method: POST

Uri: _api/web/lists/GetByTitle('<ListName>')/items(<ItemID>)/validateUpdateListItem

Body:
{
    "formValues":[
	{
	    "FieldName": "<FieldToUpdate>",
	    "FieldValue": "<ValueToUpdate>"
	}
    ]
}

Note: < … > are placeholders, replace them including the < and >.

The part to change is again the ‘FieldValue’. Managed metadata needs the format:

<term name>|<term id>

Following the example for ‘Term1’:

"FieldValue": "Term1|06b10410-338a-4e0c-b93f-5ea690fc22a9"

Take the term name, extract the term id from the filtered term (outputs from ‘Filter array’), and update the item.

body('Filter_array')[0]?['id']
Power Automate update managed metadata SharePoint

Summary

Before you can use Power Automate to update the managed metadata SharePoint column, you must extract quite a few id’s. Firstly, use the term group name to find the term group id. Once you have the group id, you can search for the term set id. As the id’s won’t change unless you change the column, you can just take them and hard-code in a flow. In the flow where the actual update will happen.

Use the group id and set id to extract the terms id, filter out the desired term, and update the field.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

1 thought on “How to update SharePoint managed metadata column (Power Automate)”

  1. Ryan says:
    November 30, 2021 at 11:10 pm

    Very helpful, thank you for this writeup! It worked a treat for me.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

NOW AVAILABLE:

The Ultimate Power Automate expressions cheat sheet
Spend your time thinking about what the flow should do, not how to do it!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • How to create a new SharePoint list column with Power Automate flowMay 22, 2022
  • How to combine expressions in your Power Automate flowsMay 18, 2022
  • Import Planner tasks with checklists into various buckets (Power Automate)May 15, 2022
  • How to get notified when Planner task was reassigned (Power Automate)May 11, 2022
  • How to extract value from XML using Power Automate flowMay 8, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme