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:-
and at the same time we are storing the files into this folder structure as follow:-
-ClientName
-DocType
-the documents
as follow:-
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?
@Expiscornovus this worked for me,, thanks a lot
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'])
Below is my test result.
@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.
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:
@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?
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
Alternatively, if you want to keep using folders you can also use the Column default value setting as well.
Below is an example of that
1. The Default value for the Client column is set to Contoso Sports for the CustomerA folder.
2. The Contracts folder inherits this value
WarrenBelz
146,745
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional