Power automate flow to auto-tag documents in SharePoint

3861
0
12-09-2022 02:30 PM
RaajRaaj
Esri Contributor
1 0 3,861

Metadata in SharePoint can be managed in:

RaajRaaj_4-1670623481598.png

 

The heart of SharePoint's Managed Metadata system is the managed terms feature. You can decide which terms you want to use for tagging data restrict users to a limited number of metadata tags for cataloging documents.

For example, assume you have an accounting department. Some of your employees may enter data such as “Acct Dept” or “Account. Dept” or “AD”.  While these may all refer to the same thing because people have entered names into the system in different ways, it will be nearly impossible to maintain consistency and retrieve information easily with these naming variations. By using the Term Store, you can enter the term as “Accounting Department”, and in every place within SharePoint that uses that field, that term will be entered consistently when referring to that specific department.  

Managed terms lend consistency to your metadata making it easier to organize and find everything.

Auto-tagging documents

To tag documents with appropriate terms/keywords, you can take advantage of SharePoint connectors in Power automate.  They can be used to check if a particular term (keyword) exists in the term store to auto-tag documents when they are uploaded to specific document libraries and create new terms if they don’t exist in the term store.

We will be using the “Send an HTTP request to SharePoint” connector to communicate with the SharePoint REST API. Using this action allows us to construct ad execute SharePoint REST API queries.

We also have the option to use the Graph API, but the app would need to be registered on Azure AD. Moreover, the “HTTP” Graph API connector is a premium connector that requires a standalone Power apps license.  Due to these limitations and given metadata management is specific to SharePoint, the SharePoint REST API is a better option.

RaajRaaj_5-1670623611770.png

Steps:

The above flow will get triggered whenever a document is uploaded into a specific SharePoint document library.

RaajRaaj_6-1670623634442.png

 

For this example, I have used the “Esri Offices” document library in “a4sp” SharePoint site collection.

Using the “Get” method in the “Send an HTTP request to SharePoint”, we can retrieve all the terms currently stored in the SharePoint org’s term store.

RaajRaaj_7-1670623654085.png

 

The output from the “Send an HTTP request to SharePoint” is in JSON format and since we are only interested in the “name” and “id” of each term, we must parse the JSON output from the above action.

The next step would be to get the “term” that needs to be assigned to all newly uploaded documents to the specified document library.

 

 

For this example, we will use the terms entered in a SharePoint list.

RaajRaaj_8-1670623688984.png

 

In this example, we are reading the last or latest entry in the SharePoint list.

We then use a “condition” to check if the term exists in the term store (within the specified term group and term set).

 

RaajRaaj_9-1670623719996.png

 

If the term already exists, then we don’t create a new entry in the term store, instead we will go ahead and update the file property by adding the keyword/term/tag.

If the term doesn’t exist, we then use the “POST” method in the “Send an HTTP request to SharePoint” action and create an entry for the new term in the term store (the term will be created within the term group and term set specified in the earlier actions). After the new term is created in the term store, we would then update the file property by adding the keyword/tag/term to the file.

RaajRaaj_10-1670623762359.png

 

The below video illustrates the above Power automate flow in action: