cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
swhitmore
Advocate I
Advocate I

Set SharePoint Column Default Values using Flow

Hi, I'm wondering if anyone knows if it is possible to set the Column Default Values for a SharePoint Online folder using Flow.

Possibly using a HTTP request?

I have come across this article SharePoint Online Update default value to a field in a list using Rest API, however I believe this only changes the default value of the site column, and not for a folder.

Thanks.

9 REPLIES 9
v-yamao-msft
Community Support
Community Support

Hi @swhitmore ,

 

It could be achieved by using SharePoint action Send an HTTP request to SharePoint.

https://docs.microsoft.com/en-us/connectors/sharepointonline/#actions

By the way, here is a doc on working with folders and files with REST, please check it for a reference:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest

Please take a try with it on your side.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-yamao-msft . I figured it could likely be done with a REST API call, but I couldn't find one that would work in SharePoint online.

 

Edit: I managed to get this action working, but not completely

Untitled.png

However this updates the default value here:

Capture.PNG

 

But I need to update it here:Untitled.png

 

 

This method works. 
 
DefaultImage.jpg
 
If you remove the default value from the library settings default value page, the column default value will take over - as per the screenshot above.
 
This might save someone typing out the text from the screenshots...  
 
_api/web/lists/GetByTitle('Documents')/Fields/getbytitle('Project Details')
accept                    application/json;odata=verbose
content-type          application/json;odata=verbose 
X-HTTP-Method     MERGE
IF-MATCH               *
X-RequestDigest    $('#_REQUESTDIGEST').val()
{'__metadata':{'type':'SP.Field'}, 'DefaultValue':'Hello Updated Value'}
 
 
 
 
Anonymous
Not applicable

@HaydenSinclair  The method you describe is exactly the same as the one stated previously. Using "/Fields/" is setting the default on the field at the library level, not on individual folders. You do not have any folders in your doc library.  If you create folders and want separate default values for a column/field on a folder level, the method you describe does not work.

 

The only way I've found to do this is via PowerShell, but that doesn't solve automating creating document libraries that contain folders with pre-set default values so that when someone drops a file into a folder, those default values are set on the document. I have a Flow that changes the value on the document based on what folder it is placed in, but that only works if the document library already exists so you can create a Flow that runs on it. I'm creating new libraries and want to preset those values within the create library Flow, since it doesn't appear that you can create a Flow from a Flow (except for admin flows).  

One way is to update the client_LocationBasedDefaults.html file.

 

Use a SP HTTP GET to read the file content and put the result into a string variable

Ex:

_api/Web/GetFileByServerRelativePath(decodedurl='/sites/yoursite/Shared Documents/Forms/client_LocationBasedDefaults.html')/$value?binaryStringResponseBody=true

 

Then you will need to build a string to add your folder defaultvalue info at the end

 

You new folder info that you will append to the file content will be something like:

 

<a href="/sites/YouSite/Shared%20Documents/yourNewFolder"><DefaultValue FieldName="udlProjectNo">YourValue</DefaultValue></a>

 

Note: If your folder contains spaces, replace spaces with %20'

 

Then write back the new file content with a SP HTTP PUT

 

_api/Web/GetFileByServerRelativePath(decodedurl='/sites/YourSite/Shared Documents/Forms/client_LocationBasedDefaults.html')/$value

 

The body will be your new default values string.

 

Microsoft should provide better api commands to do these things....

 

Hope it helps

 

Hello All,

 

Can this method to set default column value also be achieved with the new unified Graph Rest API? In case yes, can someone point me to some examples

@CoupalM 

 

And this works with the 'Send an HTTP request to SharePoint' action in flow for this?

 

If so, could you please provide some screens with the various steps and which string goes where?

The only way I can think of , which is fairly easy is to use Power Automate with a PNP powershell call. The issue with this is that you need for executing the power automate a power automate pro license, which cost around 13 euro a month.

 

connect the power automate with a runbook on azure, and use the follwing powershell command to set default value on specific folder:

 

Set-PnPDefaultColumnValues -List Documents -Field MyTextField -Value "DefaultValue" -Folder "My folder"

Or use
Set-PnPDefaultColumnValues -List Documents -Field TaxKeyword -Value "Company|Locations|Stockholm"
To assign a default value based on managed metadata.

 

I hope this helps

 

 

 

Rhiassuring
Super User
Super User

Hey there, I figured it out, and I'm super excited, so I'm posting it in all the unanswered threads - Power Automate only, no PnP fanciness needed.

https://powerusers.microsoft.com/t5/Building-Flows/Setting-the-default-column-value-of-a-subfolder-i...

______________________________________________________________


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!



Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (4,356)