cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Setting the default column value of a subfolder in a document library using Power Automate

I have a Flow that automatically creates project folders in a document library on SharePoint based on a form response and I need different folders to have different default column values to make use of searching using metadata. The Folder structure is Client/Location/Project so I want the folders in the client folder to have a default value of the client, the location to have default values of client & location and I want the project folder to have default of the previous as well as the project number.

 

The issue i'm having is that I can set the default column value for the library but I run into issues when I try to set the default values of the subfolders. The error i'm receiving is "List 'xxxxxxxxxx/xx xxxxxx' does not exist at site with URL 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.
clientRequestId: c2e9facc-fe0d-4caf-a611-25f2c6fe21b8
serviceRequestId: 28bfa59f-5061-b000-a4fc-4d19b87acc90"

 

See screenshot below of configuration:

 

bthomas_1-1611850380201.png

 

Any help would be appreciated!

 

Thanks,

22 REPLIES 22
Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous,

 

For me it's not entirely clear if you want to update the default value of a column or if you just want to update the metadata of a list item, in this case a folder.

 

So, I have created REST API examples for both scenarios. Hope this helps a bit?

 

1. Update the default value of a document library field. In this case I am setting the default value of the field to Contoso Sports.

 

URI

 

_api/web/lists/GetByTitle('@{variables('LibraryName')}')/Fields/getbytitle('@{variables('FieldName')}')

 

Headers

 

{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "application/json;odata=verbose",
  "X-HTTP-Method": "MERGE",
  "IF-MATCH": "*"
}

 

Body

 

{
  "__metadata": {
    "type": "SP.Field"
  },
  "DefaultValue": "Contoso Sports"
}

 

updatedefaultvalue_field.png

 

2. Update the value of that same field for an item in the document library. In this example I am first retrieving the ListItemEntityTypeFullName. I am using that value for the type in the second request. In this case I am setting the value of the field of the folder item to Contoso.

 

URI

 

_api/web/lists/GetByTitle('@{variables('LibraryName')}')?$select=ListItemEntityTypeFullName

 

Headers

 

{
  "Accept": "application/json;odata=nometadata"
}

 

listentitytypename.png

 

URI

 

_api/web/lists/getByTitle('@{variables('LibraryName')}')/items(1)

 

Headers

 

{
  "content-type": "application/json; odata=verbose",
  "accept": "application/json; odata=verbose",
  "IF-MATCH": "*",
  "X-HTTP-METHOD": "MERGE"
}

 

Body

 

{
	"__metadata": {
    "type": "@{outputs('Send_an_HTTP_request_to_SharePoint_-_ListItemEntity')?['body/ListItemEntityTypeFullName']}"
  },
  "@{variables('FieldName')}": "Contoso"
}

 

 

updatefolderitemvalue.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Anonymous
Not applicable

Thank you for your detailed reply, for the 2nd one I get an error saying "Invalid JSON. A comma character ',' was expected in scope 'Object'. Every two elements in an array and properties of an object must be separated by commas."

 

bthomas_0-1611914080163.png

 

However, the main issue I have and need resolving is setting a default value in a column specifically for the project name subfolder e.g. Contoso/ProjectName

 

Thanks,

Anonymous
Not applicable

I think I have the same need as the original poster - who did not seem to have gotten his issue resolved.

 

We are trying to use Power Automate to set the default column value at the folder level. Ie. corresponding to the following UI in Sharepoint - Not the general default value for the column in the document library.

MortenNB_0-1626163866003.png

 

Any ideas on how to achieve this?

Hi @Anonymous did you ever get this working.  I am trying to do the same thing

Anonymous
Not applicable

I'm assuming this was never resolved? 

 

Is there a restapi that allows us to set this setting?

Rhiassuring
Super User
Super User

There are a few open threads around this request and I figured it out today so thought I'd drop what I figured...

 

And, a warning:


🔥TWO LIBRARIES DIED IN THE MAKING OF THIS POST 🔥 


Don't try this on a Prod library! Test it out and get it working first. (Luckily I wasn't as stupid as I normally am and only tried in test sites.)

First, my goal was to set default values on sub-folders. 

Here is my Flow:

Rhiassuring_0-1659565785010.png

 

One caveat - this won't work until you've modified one default, as this seems to create the file in the background. (For myself, I have one piece of Library metadata that will default across the board, so I am going to see if I can just set that through API on its own - but wanted to post this first. UPDATE: Updating one default didn't work to trigger the HTML creation. Oh well.) 

Step 1)
Initialize a string variable.

Step 2)
Get the client_LocationBasedDefaults.html content.

Rhiassuring_1-1659565866808.png

Step 3) I have a Compose for step 3, but that's just because it kept failing based on everything I was reading, so I wanted to look at what the DEFAULT output was from this file. If you want to see, you will do this in a Compose:  

 

decodeBase64(body('Send_an_HTTP_request_to_SharePoint_-_Get_Defaults_String')?['$content'])

Step 4) Build your defaults! It's not even difficult it's just SO PICKY. Here I am setting values for 2 different folders.

Rhiassuring_2-1659565944057.png

 

 

 

 <MetadataDefaults><a href="/sites/Intranet/TestDefaults/Test1"><DefaultValue FieldName="TextTest">bad</DefaultValue></a><a href="/sites/Intranet/TestDefaults/Test2"><DefaultValue FieldName="TextTest">good</DefaultValue></a></MetadataDefaults> 

 

 

 

Step 5) Cram it back into the file and rejoice.

Rhiassuring_3-1659565986952.png

Here's what it looks like, with some more complex sends... showing that it inherits properly.

Rhiassuring_0-1659568308441.png

I've never been so happy to see those horrible little green gears. Flowers? They kind of look like ICQ flowers.

PS: This works with MMD as well but you need to structure it as -1;#LABEL|LABELGUID

 

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



jfalgoutIncworx
New Member

Thank you so much for this! I did get it to work by testing what you provided above. However, when I'm trying to do multiples of the same folder on different site columns, it completes, but only changes the first one. Any idea of my error?

<MetadataDefaults>
<a href="/sites/Projects/TestDefaults/Test1"><DefaultValue FieldName="State">TX</DefaultValue></a>
<a href="/sites/Projects/TestDefaults/Test1"><DefaultValue FieldName="Vesper Dept">Projects</DefaultValue></a>
<a href="/sites/Projects/TestDefaults/Test2"><DefaultValue FieldName="State">CA</DefaultValue></a>
<a href="/sites/Projects/TestDefaults/Test2"><DefaultValue FieldName="Vesper Dept">Projects</DefaultValue></a>
</MetadataDefaults>

Thank you for you blogpost.

In my flow, a new folder is created and then I want to set the default values for the columns.
I can run the flow successfully and the default values are set on the newly created folder, however, the the default values of the previously created folders are deleted.
In my case the file "client_LocationBasedDefaults.html" is overwritten, so that only the folder created in the flow has a default value.

How do I make sure the new value is added in to the current client_LocationBasedDefaults.html file instead of creating a new client_LocationBasedDefaults.html every time.

You can just create a condition to query for that file - if it finds it, then, just copy the text out and append your updates. If it doesn't, then, create a new one.

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



Thanks for this post but i have given it many tries doing exactly as you do but i am unable to get this working in anyway. I am able to get this working in powershell PNP (i am at the point to just build a function app for this).

It is a crucial function to have so is there perhaps more information you can give or test if this still works as expected

When you have multiple for the same folder, the syntax is different. Try something like this:

<MetadataDefaults>
<a href="/sites/Projects/TestDefaults/Test1"><DefaultValue FieldName="State">TX</DefaultValue><DefaultValue FieldName="Vesper Dept">Projects</DefaultValue></a>
<a href="/sites/Projects/TestDefaults/Test2"><DefaultValue FieldName="State">CA</DefaultValue><DefaultValue FieldName="Vesper Dept">Projects</DefaultValue></a>
</MetadataDefaults>
RathwynAE
Helper I
Helper I

Okay y'all, buckle up. I know this is more than two years old but it's basically the only post I found while trying to do this so hopefully this saves someone else the headache.

 

All kudos to @Rhiassuring whose work above was the foundation for this post. I literally would not have known where to start without them.

 

Here's how I figured out how to add new defaults to the existing defaults. Important note here that these steps assume the client_LocationBasedDefaults.html file already exists, which it will not unless at least one column default has been set through the UI. In my use-case I do not have a need to programmatically create new client_LocationBasedDefaults.html files, only update the existing one for an existing library, so I did not spend time trying to figure that out.

 

Step 1. Get the path to your client_LocationBasedDefaults.html file

Go to your SharePoint site’s document library (at the top level) through a web browser and then copy the URL, it will look something like this:

https://mycompanyonline.sharepoint.com/sites/mysubsite/LibraryName/Forms/AllItems.aspx

or

https://mydomain.sharepoint.com/sites/intranet/LibraryName/Forms/AllItems.aspx

Now replace the “AllItems.aspx” at the end of your URL with “client_LocationBasedDefaults.html” like 

https://acmecorponline.sharepoint.com/sites/RR-Catalog/Shared%20Documents/Forms/client_LocationBasedDefaults.html

 

Step 2. Add the “Send an HTTP request to SharePoint” action in your Flow. Pick your site and GET as the method. For a URL like my above example, the Uri would be as follows:

_api/Web/GetFileByServerRelativePath(decodedurl='/sites/RR-Catalog/Shared%20Documents/Forms/client_LocationBasedDefaults.html ')/$value?binaryStringResponseBody=true

Don’t populate Headers or Body sections.

 

Step 3. Modify the existing client_LocationBasedDefaults.html content to be able to use later.

The output of Step 2 is going to be the current folder defaults for that library. It will look something like this: (line breaks added for readability – don’t put line breaks in your actual Flow!)

<MetadataDefaults>

<a href=\"/sites/RR-Catalog/Shared%20Documents/Anvils\"><DefaultValue FieldName=\"Class\">Anvil</DefaultValue></a>

<a href=\"/sites/RR-Catalog/Shared%20Documents/Disguises\"><DefaultValue FieldName=\"Class\">Costume</DefaultValue></a>

<a href=\"/sites/RR-Catalog/Shared%20Documents/Cooking%20Utensils\"><DefaultValue FieldName=\"Class\">Appliance</DefaultValue></a>

<a href=\"/sites/RR-Catalog/Shared%20Documents/Jets%20%26%20Motors\"><DefaultValue FieldName=\"Class\">Transport</DefaultValue></a>

</MetadataDefaults>

We need to insert our new defaults into this file before the </MetadataDefaults> closing tag, and we need to remove all the backslashes (\) - the string you put together to put in the HTTP request later should have NO backslashes in it. Don't replace them - remove them. Use a compose and nest a decodeBase64 formula within the replace formula:

replace(decodeBase64(body(‘Step_2_Action’)?['$content']), '\', '')

Then we need to remove the closing Metadata tag so that we can append our changes in a later step:

substring(outputs('Previous_Compose'),0,sub(length(outputs('Previous_Compose'')),19))

 

Step 4. Determine your new defaults.

All of the folders in the above example are located at the top level of the library. As you go deeper into the folder structure the syntax of the metadata defaults simply extends the URL. For example, “Shared Documents > Jets & Motors > Jet Bike Kit” would be:

<a href=\"/sites/RR-Catalog/Shared%20Documents/Jets%20%26%20Motors/Jet%20Bike%20Kit\"><DefaultValue FieldName=\"Class\">Transport</DefaultValue></a>

Notice how Jet Bike Kit became Jet%20Bike%20Kit and Jets & Motors became Jets%20%26%20Motors? If you are building your own path out of dynamic values in Flow, you have to account for the required formatting. Replace all spaces with %20:

replace({dynamicvalue}, ‘ ’, ‘%20’)

Look out for other types of special characters in your folder names. Don't have any if you can help it, but if you do you will have to replace them with what SharePoint actually sees - look at the URL you get when you navigate to that folder in the library to get an idea of what SharePoint sees as the actual folder path and name. Once you know that, you can add steps in the flow to replace or remove certain special character from the dynamic values before you plug them into your final string. In this case, we know that & = %26, so we would write a replace formula for the & symbol:

replace({dynamicvalue}, ‘&‘, ‘%26’)

This only applies to the path, the default value itself does not need to be transformed.

In my scenario, I am updating a folder’s metadata based on values in a list item. The list items are categorized by the top-level folders, meaning I have a field on the list that tells me if the item is Anvils, Disguises, Cooking Utensils, or Jets & Motors. So, I would do something like this:

2023-06-16_18-14-20.png

replace(replace(triggerOutputs()?['body/Class'], ‘ ’, ‘%20’), ‘&’, ‘%26’)
replace(triggerOutputs()?['body/Title'], ‘ ’, ‘%20’)
<a href="/sites/RR-Catalog/Shared%20Documents/@{outputs('Compose_Path_Class')}/@{outputs('Compose_Path_Title')}"><DefaultValue FieldName="SKU">@{triggerOutputs()?['body/SysID']}</DefaultValue></a>

 

Step 4a. What if I want to add more than one default value to a folder?

If you need to set multiple defaults for the same folder, you need to do that within the <a> tag, so you wouldn’t close the tag until you’ve covered them all. Add more by adding additional <DefaultValue> tags after the URL. For example:

<a href=\"/sites/RR-Catalog/Shared%20Documents/ Jets%20%26%20Motors/Tennis%20Balls\"><DefaultValue FieldName=\"Class\">Transport</DefaultValue><DefaultValue FieldName=\"Department\">Sports</DefaultValue></a>

In this case you would likely want to build each <DefaultValue FieldName=\"{column}\">{defaultvalue}</DefaultValue> statement separately and then combine them all into one statement with the folder path. I prefer compose actions over variables, but it may make more sense to have a string variable and an append to string variable action if you have a lot of default values you want to add to a single folder.

 

Step 4b. What if I want to update more than one folder at a time?

If you will be adding multiple folders in one flow, that basically equates to adding multiple lines. I would recommend using an apply to each if possible (and/or call a subflow) to go through the steps to modify and combine your default values for each folder you would want to update. In this scenario, you would have to add an additional action after my Compose New Path that is an append to string variable so that your output will capture all the options. Then wherever I am plugging in outputs('Compose_New_Path') you would plug in the string variable.

 

Step 5. Combine the existing with the new.

This is thankfully a simple concat:

concat(outputs('Compose_LocationBasedDefaults'), outputs('Compose_New_Path'), ‘</MetadataDefaults>’)

 

Step 6. Upload it back to SharePoint

Use the “Send an HTTP request to SharePoint” action again, with PUT as the Method and a Uri like:

_api/Web/GetFileByServerRelativePath(decodedurl='/sites/RR-Catalog/Shared%20Documents/Forms/client_LocationBasedDefaults.html ')/$value

 

In the body, enter the output from your concat in Step 5.

 

In my flow I ended up combining a bunch of these steps, but I would strongly recommend you create each one separately first and make sure it works on a test library before doing that yourself. I would also recommend saving the original output from the first HTTP request and adding that into a compose while you’re building it, because as you test you will be appending on to your previous tests, which can compound mistakes and make it hard to tell when you’ve succeeded. If you have the OG code ready in a compose, you can swap that output back into your flow in between real tests to ‘reset’ the file.

Hi all! You mentioned that it works for Managed Metadata Column, but we need specific template 1;#LABEL|LABELGUID. But I don't understand where we can find the first number. With random number it doesn't work. Do you know the secret, how we need to set those values?) 

Go to the Term Store (where you created the Managed Metadata in the first place - can be found by adding /_layouts/15/SiteAdmin.aspx#/termStoreAdminCenter to the end of your site address) click on the term you want the ID for, then click on the "Usage settings" tab and copy the Unique identifier:

RathwynAE_0-1691445873827.png

 

Then you want it formatted like this:

Apptio|310483e1-56b3-4f66-a014-7bd52c0362fd

 

This is what you will need whenever referencing the Managed Metadata basically anywhere that's not a user interface - like if you want to Switch on it in a Power Automation flow, the Case would be in that same format.

jasonkirk
Frequent Visitor

Both posts here from @Rhiassuring and @RathwynAE were great here and I was almost there. 

I have created a Team create form in a powerapp that querys the Term Store for the Customer so that the users can have their documents automatically tagged from the start. 

I got as far as being able to set the managed metadata default value on to a column, but when testing, the documents are not being 'tagged' and the values when clicking on the column in the default column values settings, the defaul setting is not actually set.

I tried creating the client_LocationBasedDefaults.html file, but had no luck. It really feels like that is the key. Manually setting it isnt a solution as the customer wants this flow to skip needing to touch the site before handing it over to the owners. 

Anyone got any ideas about creating that file? 

Hi Karina, 

From my work this week, i have found that that number is always '-1', so you can build the structure in a compose action. It may have not been working as you were using '1'?

boing0
Regular Visitor

The first number isn't the standard -1 WssId, it's the ID for the metadata term in your site's locally cached TaxonomyHiddenList:

/sites/YourSiteName/Lists/TaxonomyHiddenList/AllItems.aspx

 

Browse to that list and show the columns 'IdForTerm' and 'ID' -- the ID is what you need to compose your string 'ID;#LABEL|LABELGUID'. The IDs are auto-increment and apply to any metadata used in the Site Collection, doesn't matter what term set they belong to or what List they are used in. When you manually set a metadata value (via a form, using the library column defaults page, etc.) and use a term for the first time it will add it to the TaxonomyHiddenList and you'll get a new ID generated.

 

Even thought you know what the next ID number will be, updating client_LocationBasedDefaults.html with new, sequential IDs won't work since it doesn't actually add them to the TaxonomyHiddenList. You need to get the terms added to TaxonomyHiddenList first so you can retrieve their IDs to then write to client_LocationBasedDefaults.html. You could create a test List, use Flow to loop through every term in your set and assign it to a List item. That would populate TaxonomyHiddenList with all your terms and IDs so you could then query that list to get the IDs you would need. This is what I've had to do since I don't have permission to run Powershell.

Hi RathwynAE,

Can you please share the Screen shot of the full flow because I am trying to do the same but I am getting errors.

Hey there,

 

I also had a customer with the request to create the client_LocationBasedDefaults.html file, without manual input before. So I fiddled around a bit and found a PowerShell script to create a client_LocationBasedDefaults.html file: https://github.com/msisgreat/ps/blob/master/Upload_client_LocationBasedDefaults.ps1

 

I tried converting this into a flow and got this working:

Save Default Values.PNG

Hope this helps! 😊

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (4,570)