Skip to main content

Notifications

Community site session details

Community site session details

Session Id : ET4mBQKVIXksd7vAOlt2Q6
Power Automate - Building Flows
Answered

Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

Like (0) ShareShare
ReportReport
Posted on 3 Jan 2024 11:47:46 by 1,542 Super User 2024 Season 1

We are trying to benefit from using folder structures and managed metadata to store our SharePoint documents. so i created a term group >> with 2 term sets >> named "client" and "Doc Type", as follow:-

 

johnjohnPter_1-1704282315180.png

 

 

and at the same time we are storing the files into this folder structure as follow:-

 

-ClientName

    -DocType

        -the documents 

 

as follow:-

 

johnjohnPter_0-1704282240726.png

 

 

now i want to know if it is possible to populate the new documents with the 2 managed metadata fields based on the Parent folder name and the subfolder name? for example if i upload a document inside the Proposals sub-folder which is under ClientC parent folder>> to have the Client metadata for the newly added document = ClientC & the DocType metadata = Proposal ? and so on.. can anyone advice?

 

 

  • johnjohnPter Profile Picture
    1,542 Super User 2024 Season 1 on 09 Jan 2024 at 14:13:49
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    @Expiscornovus this worked for me,, thanks a lot

  • Verified answer
    Expiscornovus Profile Picture
    31,652 Most Valuable Professional on 04 Jan 2024 at 10:08:43
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    Hi @johnjohnPter,

     

    I think in the same thread they also tried add new defaults without removing the old ones. But if you have already tried it lets go for your own suggested approach.

     

    I would use the Full Path property and split it on the / character. In that case you could use the 2nd and 3rd item of the returned array.

     

    Below is an example

     

    1. Via a split expression the Client and DocType are retrieved

     

    Client

     

    split(triggerOutputs()?['body/{FullPath}'], '/')[1]

     

     

    DocType

     

    split(triggerOutputs()?['body/{FullPath}'], '/')[2]

     

     

    2. Those are used in a couple of HTTP requests to retrieve the term id of the corresponding label

     

    URI Client

     

    _api/v2.1/termStore/groups/@{variables('TermGroupId')}/sets/@{variables('ClientTermSetId')}/terms?$filter=labels/any(a: a/name eq '@{split(triggerOutputs()?['body/{FullPath}'], '/')[1]}')

     

     

    URI DocType

    _api/v2.1/termStore/groups/@{variables('TermGroupId')}/sets/@{variables('DocTypeTermSetId')}/terms?$filter=labels/any(a: a/name eq '@{split(triggerOutputs()?['body/{FullPath}'], '/')[2]}')

     

    I also got a blog about that approach:

    https://www.expiscornovus.com/2022/12/29/get-terms-by-label/

     

    3. With concat expressions they are used in an update file properties action (as a custom value)

     

    Client

     

    concat(split(triggerOutputs()?['body/{FullPath}'], '/')[1], '|', outputs('Send_an_HTTP_request_to_SharePoint_-_Client')?['body']['value'][0]['id'])

     

     

    DocType

     

    concat(split(triggerOutputs()?['body/{FullPath}'], '/')[2], '|', outputs('Send_an_HTTP_request_to_SharePoint_-_DocType')?['body']['value'][0]['id'])

     

     

    updatemmsflow.png

     

    Below is my test result.

     

    testrun_mms_terms.png

  • johnjohnPter Profile Picture
    1,542 Super User 2024 Season 1 on 04 Jan 2024 at 01:03:36
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    @Expiscornovus it is not possible to set the column default value using power automate, i tried this long time ago, and when i set a default value for a new column all the old values got removed. so in other words if we want to set a default value using power automate or SharePoint rest api, we will need to do it for all existing folders.. as when you set this for a single folder this will reset the values for all the other folders.

  • Expiscornovus Profile Picture
    31,652 Most Valuable Professional on 03 Jan 2024 at 15:43:11
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    Hi @johnjohnPter,

     

    Good to know you prefer folders instead of doc sets đź‘Ť

     

    I would still suggest to look into the column default value setting. It should be possible to automate that setting for each new folder with a flow as well. 

     

    @Rhiassuring has shared a nice solution about updating these settings via a Power Automate flow:

    https://powerusers.microsoft.com/t5/Building-Flows/Setting-the-default-column-value-of-a-subfolder-in-a-document/m-p/1701525/highlight/true#M188650

     

  • johnjohnPter Profile Picture
    1,542 Super User 2024 Season 1 on 03 Jan 2024 at 15:15:13
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    @Expiscornovus document set as become somehow an old approach to manage documents with the flat structure and modern UI and more collaboration rather than having a documents repository.

     

    i know that i can set the default values for folders, but users will keep adding new folders, and they find it difficult to set the default values for the folders by themselves + this will require me to grant them additional permissions to manage the libraries which i do not want to provide.

     

    so i find my approach simple and straight forward, users have to only create a new term for the new client and create a folder with the same name as the client.. then the workflow will populate the metadata accordingly. what do you think?

     

     

  • Expiscornovus Profile Picture
    31,652 Most Valuable Professional on 03 Jan 2024 at 13:19:12
    Re: Can i populate the created documents with managed metadata terms based on the Parent Folder name and sub folder name

    Hi @johnjohnPter,

     

    Your requirements sound a lot like the document sets feature. You could create a document set per customer and use the shared columns feature. Below is a thread where I shared an example

    https://powerusers.microsoft.com/t5/Building-Flows/Inheriting-Metadata-from-parent-folder-when-folder-document-is/td-p/2188144

     

    Alternatively, if you want to keep using folders you can also use the Column default value setting as well. 

    https://stackoverflow.com/questions/55704748/how-to-inherit-folders-properties-when-adding-a-new-file-sharepoint

     

    Below is an example of that

     

    1. The Default value for the Client column is set to Contoso Sports for the CustomerA folder.

     

    contososports_defaultvalue.png

     

    2. The Contracts folder inherits this value

     

    defaultvalue.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started