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

Copying folder structure AND renaming the new root folder using dynamic content?

Hello,

 

Hoping someone can help me, as I've read numerous posts on this but still struggling as I'm very new to Power Automate.

 

The closest solution I have found is this one, but due to my lack of experience in that area, I cannot get it to work for my site because I don't fully understand how it works.

 

What I am trying to set up

A flow which:

1. Automatically duplicates a default folder structure in a document library, structure is:

  • Folder A
    • Sub-Folder B
      • File A (excel file, always standard)
    • Sub-Folder C
    • Sub-Folder D
    • Sub-Folder E

2. Automatically renames the newly created Folder A based on one of the values in the latest addition of a list item

 

Where I have got to so far

I have created a simple flow which achieves point 1. above (can't seem to paste screenshots, so will describe below):

- When an item is created: [site address]: [list name]

- Copy Folder: [current site address]: [folder to copy] (this is a folder structure within a document library): [destination site address]: [destination folder] (a different document library): [fail this action]

 

The list imports data from MS forms. One of the columns in the list contains data which is to be used to rename Folder A in the newly duplicated folder structure.

My question is, how do I set this up dynamically so that each time the new folder structure is created, Folder A automatically gets renamed using the data in Column X of the list. Is this possible?

 

Any help appreciated, many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @User_2ja7Dhh89,

 

Yes, you could use the column value get from the MS Form to update the new created Folder, instead of Update file properties action, you should use the Send an HTTP request to SharePoint action to update the folder name:

Method: Post

URI: _api/web/GetFolderByServerRelativeUrl('Hub/@{body('Copy_folder')?['DisplayName']}')/ListItemAllFields

Headers:  "Accept""application/json;odata=verbose",

                "X-HTTP-Method""MERGE",
                "If-Match""*"

Body:  {
            'Title': 'NewFolderName',
            'FileLeafRef': 'NewFolderName'
           }

Annotation 2020-05-15 105633.jpg

 

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

 

View solution in original post

11 REPLIES 11
v-litu-msft
Community Support
Community Support

Hi @User_2ja7Dhh89,

 

Yes, you could use the column value get from the MS Form to update the new created Folder, instead of Update file properties action, you should use the Send an HTTP request to SharePoint action to update the folder name:

Method: Post

URI: _api/web/GetFolderByServerRelativeUrl('Hub/@{body('Copy_folder')?['DisplayName']}')/ListItemAllFields

Headers:  "Accept""application/json;odata=verbose",

                "X-HTTP-Method""MERGE",
                "If-Match""*"

Body:  {
            'Title': 'NewFolderName',
            'FileLeafRef': 'NewFolderName'
           }

Annotation 2020-05-15 105633.jpg

 

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

 

Hi there @v-litu-msft ,

 

Thanks so much for the reply. It's really useful and has gotten me further than before!

 

However, the flow still gets stuck and says '1 retry' on the 'Send an HTTP request for SharePoint' part. When I click view, it looks as though everything is fine (it's even picked up the dynamic content from my List as to the folder name), but for some reason it doesn't complete the action, and the folder name does not change.

 

I have a feeling it's something to do with what I have written in the body? In your example I see you have used expressions. For mine, I just put the dynamic content of the relevant field in the SharePoint List here. Am I doing something wrong? Everything else is exactly as you have written it.

 

Many thanks again.

Hi @User_2ja7Dhh89,

 

Actually, the expression is a kind of dynamic content, too. So the root of the reason not the expressions. You could even input a fixed value into the Body to rename the folder.

 

Could you please check the connection of the Send an HTTP request action?

 

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

 

Hi @v-litu-msft,

 

Thanks.

 

Please could you just explain to me how to check the connection? When I click settings on the action, it shows My connections and my e-mail address associated with my O365 account, which is where I am building the flow so I think that is correct.

 

Maybe I need to somehow connect to the SharePoint site? Although I would have thought that happens in the 'Site Address' field.

 

By the way: the status says 'Bad Gateway', so I'm wondering if the request is being sent over the SharePoint site, it must need a permission somewhere if it's being blocked?

Hi @User_2ja7Dhh89,

 

You could check the connection whether valid when you test it, click the Review connections and actions, if they are green mark, it is valid:

Annotation 2020-05-22 160654.jpg

 

Annotation 2020-05-22 160840.jpg

 

Annotation 2020-05-22 160859.jpg

 

If you assume it is a permission issue, you could confirm you whether have edit permission:

https://support.office.com/en-us/article/customize-permissions-for-a-sharepoint-list-or-library-02d7...

 

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

@v-litu-msft 

 

Hi there, Unfortunately I still cannot get this to work. I have reviewed the connection; it is fine and has a green tick. I am also an Owner of the site, so no permissions problems there.

 

The error messages changes each time. Sometimes it runs and just times out (and doesn't rename the folder). Sometimes it says 'Cannot read property 'properties' of undefined' but doesn't show where to edit the flow.

For the benefit of anyone else who arrives at this solution, but cannot get it to work. With a lot of trial-and-error. I have this method working.
The sole issue I was having was with the Uri syntax:
URI: _api/web/GetFolderByServerRelativeUrl('Hub/@{body('Copy_folder')?['DisplayName']}')/ListItemAllFields

Try as I might, I couldn't get it to work by substituting 'Hub/' with the path to the new folder from my subfolders. This method extracts the path itself from the 'Copy folder' step.
For the most part, I used the original suggestion, but the amendments I made to make it work were:
1. Initialise 2 string variables (You could probably do this with one if you have the knowhow...), I called these 'varPathTrim' and 'varPath';
2. Add a 'Set Variable' AFTER the 'Copy Folder' step. This one is for 'varPathTrim'. In the value field, I used this function:

substring(outputs('Copy_folder')?['body/Path'],1,sub(length(outputs('Copy_folder')?['body/Path']),1))
This is to take the path of the newly-created folder and remove the leading '/', as this causes the 'Send an HTTP request...' step to fail.
3. If you have the knowhow, you could combine this with step 2, but I added another 'Set Variable' underneath the previous one for 'varPath' to further amend the path and remove any spaces and replace them with %20, so that the path is a URL:
replace(variables('varPathTrim'),' ','%20')
4. Now to the 'Send an HTTP request to SharePoint' step. I followed the instructions as above, but for the 'Uri' field I used:
_api/web/GetFolderByServerRelativeUrl('@{variables('varPath')}')/ListItemAllFields.

...and presto! it works.
 

Thank you.

failed many times cause of that one dot after ListItemAllFields.

it works well.

Hey!

Thanks for the useful tip!  I've consolidated your functions and removed the need to create variables for them as well!

This is useful for when you use conditionals, since you cant set variables within a branch - it has to be top-level.  Instead, you can just use the "Add dynamic content" button from the Uri field and Paste this in the "Expression" tab:
replace(substring(outputs('Copy_folder')?['body/Path'], 1, sub(length(outputs('Copy_folder')?['body/Path']), 1)), ' ', '%20')

Replace "Copy_folder" with whatever you've named the Action that generates the folder path. Just make sure that this function replaces the "Hub/" section in your Uri.  Here's what it should look like in your Uri field:
_api/web/GetFolderByServerRelativeUrl('@{replace(substring(outputs('Copy_folder_2')?['body/Path'], 1, sub(length(outputs('Copy_folder_2')?['body/Path']), 1)), ' ', '%20')}')/ListItemAllFields

I would not have figured this out without your help, so thank you! I hope this is useful to you as well.

AndreasO
Frequent Visitor

In case someone else trips on this. The method works, but if you like me want a folder renamed with say a "[Date] + [Title]" you have to remember that standard date formats use "/" as a separator -- which is illegal in folder names!

It'll just hang on the Post HTML step with no failure. 


Example: dd/MM/yyyy will give you the output 31/12/2023 -- which will fail.

 

Initialize a variable early after your Get request and use a FormatDateTime expression to fix it. 

 

Example for dynamic content:

formatDateTime(outputs('Get_response_details')?['body/r78d9d9a76e48412a98720e9706d59f14'], 'dd.MM.yyyy')
Note that with dynamic content you omit the '' before the value. 
AndreasO
Frequent Visitor

For the record, it will also hang if the last character in the filename is whitespace. 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,804)