cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bthomas
Frequent Visitor

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,

6 REPLIES 6
Expiscornovus
Super User
Super User

Hi @bthomas,

 

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

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,

MortenNB
New Member

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 @bthomas did you ever get this working.  I am trying to do the same thing

EdwardChong
Frequent Visitor

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

 

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events happening this month - don't miss out!

 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,089)