cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Flow made to copy folder to subsite then delete from main site, delete not working

Hi Guys,

 

Someone made us this flow to archive old job folders. It used to work fine but noticed now that it doesn't. What it does is look for jobs that are marked "Quoted" and over 120 days old and moves them to a subsite and then is supposed to delete the one in the main site.

 

It's working to move them, but failing on the delete. Would someone be able to look at the attached and let me know how to fix it?

 

This is the error I get: 

 

{
"status": 404,
"message": "Item Not Found\r\nclientRequestId: b0f8722c-628b-4e2c-8af6-40e511231f75\r\nserviceRequestId: b0f8722c-628b-4e2c-8af6-40e511231f75"
}

 

Flow.png

15 REPLIES 15

@Galikin It would be helpful to know which part of the flow is erroring out. Can you upload a screenshot of a failed flow run. The error indicates the item wasn't found. Also if you are able to upload a few screenshots that make it easier to read the flow—it would be helpful. It's a bit hard to read each action.

Hi mate,

 

Thanks for the response. The flow fails on the part when it comes to deleting the folders that were moved. It moves the files that meet the requirements but then fail to delete them from the main site. I've attached photos (could only attach 3 so I put the first one in this response).

 

Flow1.png

@Galikin We'll need to troubleshoot this. I would recommend you use a Filter Array action instead an Apply to Each and Condition action. It would be a lot more efficient especially if you have a lot of folders to go through.

 

You can reference a recent video tutorial that covers the Filter Array action and how to use it. 

Create a New Flow

Create a new Scheduled Cloud flow with a recurrence trigger (you can set it later). Insert a List folder action only (you don't need the variables). 

Create a Dynamic Timestamp

I would recommend using a few actions to create a dynamic timestamp which you can use to check against the folder's Last Modified date. The Scope action is optional, however I find it can come in handy if you need to quickly copy these actions to use in different flows.

 

creativeopinion_8-1694660896851.png

 

Add a Convert time zone action to convert the current time to your local time zone. In the Base time field, insert the utcNow() function. Select (UTC) Coordinated Universal Time as the Source Time Zone. For the Destination Time Zone, you can select your local time zone. For the Format String select Round-Trip

creativeopinion_2-1694659293279.png

Next add a Compose action to store the number of days you'd like to add/remove from the current date. A positive number will add days, a negative number will subtract days. In your case, enter -120.

creativeopinion_6-1694659941196.png

 

Add another Compose action to store today's date. This is optional, but it can help with troubleshooting and it also allows you to format today's date to be used elsewhere in your flow.

Use an expression and insert the Converted time dynamic content from the Convert Time Zone Action. 

formatDateTime(body('Convert_time_zone'), 'yyyy-MM-dd')

creativeopinion_5-1694659848017.png

 

Add one more Compose action to store the dynamic date. This will be the date that was 120 days ago. You'll need another expression. Use the addDays() function. It takes 3 parameters.

addDays([date to add/remove days from], [number of days to add/remove], [date format] )

This is what my expression looks like:

addDays(body('Convert_time_zone'), outputs('Compose_-_Days_to_Add_or_Remove'), 'yyyy-MM-dd')

Important: Add T00:00:00 after the expression.

 

By using a Compose action to store the number of days to add/remove you can easily alter this expression by editing the Compose action with the number of days. 

creativeopinion_9-1694660919089.png

Filter Array

Add a Filter Array action to your flow. Although it looks like you can only insert a single condition you can use multiple conditions with the Advanced Mode

 

You will need a text editor as the Advanced Mode is impossible to edit in. Build out your expressions in the basic mode and combine them in a text editor. 

 

Your first condition is to check if the folder is a folder. 

creativeopinion_0-1694441595689.png

Click Edit in advanced mode and copy the entire expression into a text editor.

creativeopinion_1-1694441644791.png

Switch back to basic mode and compose your next condition.

 

In your case, you are checking to see if the DisplayName is not equal to Forms.

creativeopinion_2-1694441694335.png

Switch back to basic mode and compose your next condition. In the first value field insert the Last Modified dynamic content from the List Folders action. Change the operator to is less than (or is less than or equal to) and insert the outputs from the Compose action that is holding your dynamic timestamp.

creativeopinion_0-1694698841311.png

Click Edit in advanced mode and copy the entire expression into a text editor.

Build the Expression

Your text editor should now have three expressions:

creativeopinion_1-1694699041376.png

 

Delete the @ symbol from the second and third expression and add a comma to the end of the first and second lines.

creativeopinion_2-1694699110025.png

 

Because you'd like your condition to look and see if if the items returned is a folder AND is not equal to Forms AND has a last modified timestamp less than your timestamp (which is 120 days from today). You'll need to wrap your entire expression with the and() function.

 

Place your cursor after the first @ symbol and type in and with an opening bracket.

creativeopinion_3-1694699221667.png

 

Move your cursor to the end of the expression and add a closing bracket. 

 

creativeopinion_5-1694699253161.png

 

Your expression should look like this:

@and(equals(item()?['IsFolder'], true),
not(equals(item()?['DisplayName'], 'Forms')),
less(item()?['LastModified'], outputs('Compose_-_Dynamic_TimeStamp')))

Tip: You can add additional conditions, separate each one with a comma and ensure the and() or the or() operator is wrapping all the appropriate conditions. 

 

Copy the entire expression from your text editor and paste it back into the Filter Array advanced editor. 

creativeopinion_8-1694442136328.png

Count Items Returned

Whenever I use a Filter Array action, I always add a Compose action after it to count the number of items returned. This will help with troubleshooting. 

Add a Compose action and insert an expression. Use the length() function to return the count of items. 

 

creativeopinion_9-1694442462561.png
Insert your cursor between the brackets and switch back to the Dynamic content tab and insert the Body dynamic content from the Filter Array action. 

creativeopinion_10-1694442551033.png

Run a test.

 

Click on the Compose action with the Folder count to confirm the number of folders returned. 

creativeopinion_11-1694442690538.png

Add a Condition

Since you are running this flow with a Recurrence trigger, there may be times where there aren't any folders that match your criteria. Before continuing on with the flow, you need to add a Condition action to check the number of items returned from the Filter Array action. 

 

Insert the outputs from the Compose action above into the first value field. Change the operator to is not equal to and enter a zero into the second value field.

creativeopinion_13-1694700391254.png

 

Get Filter Array Folders Path

Next, you need to gather the paths of the returned folders so that you can loop through those (as you have in your original flow).

 

Add a Select action into the YES branch (if the number of items doesn't equal zero, then the flow can continue on). Insert the Body outputs from the Filter Array action in the From field. Select the icon to the right of the Map field to switch the mode to text mode. You need to add an expression.

creativeopinion_14-1694700461427.png

 

If you look at the outputs of the Filter Array action from your previous flow run, you'll see the key for the path. It's 'Path'. You'll need that text in your expression. 

creativeopinion_12-1694443531439.png

Insert the item() function, question mark, square brackets and single quotes. Keep this expression handy as you'll be using it later as well. To access any value from a Filter Array action you will need the key. The key is the text in RED between the single quotes.

item()?['']

To return the Path, you need to insert Path between the single quotes. Your expression will look like this:

item()?['Path']

creativeopinion_15-1694700536960.png

 

Run a test.

 

The Select action will return an array of folder paths.

creativeopinion_25-1694445414942.png

 

Loop through Each Folder Path

Add an Apply to Each action to loop through each folder path. Insert the outputs from the Select action (aka the Array of Folder Paths.)

 

For troubleshooting purposes, insert a Compose action to store the Current Item dynamic content. 

creativeopinion_16-1694700595620.png

 

 

Add a Get folder metadata using path action (just like you had in your original flow). Insert the outputs from the Compose action above since that action will hold the current folder path being looped through.

 

creativeopinion_17-1694444000311.png

 

Add a Get file properties action (just like you had in your original flow). Insert the ItemID dynamic content into the Id field.

creativeopinion_26-1694445509182.png

Compose Actions for Dynamic Content

This part is optional. Add compose actions to store some dynamic content of the current folder being looped through. I've chosen to group these Compose actions into a Scope action to make it easy to collapse them with a single click. This isn't necessary for the flow to run—however, it can help with troubleshooting. 

creativeopinion_6-1694699482779.png

 

Copy Folder to Subsite

Use the Copy folder action to copy the current folder being looped through to your subsite.

creativeopinion_7-1694699510848.png

Ensure that you insert the Identifier dynamic content into the Folder to Copy.

creativeopinion_8-1694699601046.png

 

Delete Folder from Main Site

Since Power Automate doesn't have a delete folder action, you'll need to use the Send an HTTP request to SharePoint action.

 

Select your site address and choose DELETE as the method. In the Uri field enter:

_api/web/GetFolderByServerRelativeUrl('/sites/[site]/[folderpath])

Replace [site] with your site and insert the Full Path dynamic content from the Get file Properties action or the dynamic content from the Get folder metadata using path action. They both return the same result.

creativeopinion_9-1694699804993.png

creativeopinion_10-1694699966114.png

Outputs of the Path dynamic content.

creativeopinion_11-1694700055080.png

Outputs of the Full Path dynamic content

creativeopinion_12-1694700077827.png

 

Run a test!

 

Hope this helps!

If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response!

👉Watch my tutorials on YouTube
👉Tips and Tricks on TikTok

Thanks for this mate. I'll check it out and looking forward to seeing the rest of it. 🙂

 

[edit] I've got this all added in a new flow and working to where you got up to, looking forward to the rest and thank you for taking your time mate.

@Galikin I need a bit of clarity as to what is going on in this section of your flow.You talk about moving files and folders.

 

Are you using the condition action to filter out Files or Folders that meet your condition criteria? 

 

creativeopinion_0-1694571565841.png

 

Can you clarify if you are looking to move all files within a folder or only files that meet the criteria? 

 

Hi Mate,

 

Yes there I'm looking to move all folders (and all the files and subfolders in that folder) that meet the criteria of having a Job Status of "Quoted", Content Type of "Job Folder" & Modified Date is more than 720 days ago.

 

It then should copy all folders (and files in those folders) that meet that critera to our subsite and then delete that folder from the main site. Although I suppose we could maybe use the move command rather than copy and then delete? Copy first then delete is just how the previous person set this up.

@Galikin In my testing, I'm unable to return any column dynamic content that I've assigned to my folders. So I'd first like you to confirm that you are able to return the column dynamic content from your folders.

Can you add three Compose actions directly under the Get file properties action to store each of the dynamic content in your Condition action... and run a test?

creativeopinion_1-1694573788251.png

It should look something like this. Can you take a screenshot of those outputs from your run? To clarify, the Compose actions should have output values. Since the Apply to Each action will loop through all folders, just one screenshot will be enough. Hopefully you have a folder that meets your criteria.

 

Also, can you upload the expression you are using to get the modified date. I think we can rework that.

 

 

 

see attached mate. I think it's working? Well except maybe the date one now.

 

Here is what I was using before as the exppression: 

sub(ticks(body('Get_file_properties')?['Modified']),ticks(convertFromUtc(addDays(utcnow(),-730),'AUS Eastern Standard Time')))

@Galikin

I just added a section to my original post called Create a Dynamic Timestamp. I'd recommend adding this to your flow instead of using the expression you have as this will give you an actual timestamp rather than ticks. 

 

Also, can you adjust your Compose action that has the Job Status dynamic content to store the Job Status Value dynamic content instead?

 

Before looping through the list of returned folders, would it make sense to filter out folders that are only 120 days old? Or, would it make more sense to check the contents of the folders to see if the contents are 120 days old—copy those first, then check to see if the folder is empty before deleting it?

 

Or it's it assumed that if the folder is 120 days old, everything in that folder needs to be moved? Can you provide a bit more clarity on this? 

Hi Mate,

 

Added your dyanmic date thing and changed the Compose - Job status to use Job Status Value instead.

 

It would be assumed that if the folder is 120 days old everything in that folder is to get moved. Also would make more sense to filter first the jobs that only meet the critera and then just copy to subsite and delete or just use move instead (as i think that copies it to the subsite and deletes in 1 go) as that would be faster wouldn't it?

@Galikin To clarify, when you say "filter first the jobs".. are you referring to files? I have always had issues with the Move file action. It's pretty picky. The metadata columns in your subsite have to match the site you are moving the files from. Otherwise it'll error out. 

 

If it's assumed that all files in a folder that is 120 days old has to be moved, you could improve the efficiency of your flow by filtering out the folders that are 120 old first and just copy each file in the folder. Again, this is only if EVERYTHING in the folder has to be moved over. 

 

Confirming that this is correct..?

Yes that's correct, the folder and it's entire contents inside are to be moved if the main folder is 120 days old.

@Galikin I've updated the original post with the rest of the instructions and have altered them a bit. Since you are using a recurrence trigger, you will need to add a condition to check if there are any folders that match your criteria—otherwise your flow will fail if the Filter Array ends up being empty. 

 

The Select action and Apply to each action can then be moved into the YES branch. You will need to alter your Filter Array action expression to check for folders that are 120 days old (instructions are in the original post).

creativeopinion_17-1694700658630.png

This will be a more efficient way of running your flow to filter out the folders first, than loop through them. Reference this YT Tutorial I recently uploaded that covers the Filter Array action. 

 

Since there isn't a Delete folder action, you'll need to use a Send HTTP Request to SharePoint action to complete the folder deletion. 

 

Hope this helps!

Thanks mate, I'll have a look through this and let you know how I go (sorry off sick atm). Only thing I don't see is the filter to make sure the folder has a Job Status Value of Quoted in addition to being 120 olds. Where would I add this in?

@creativeopinion Also could you show me a screenshot of the whole flow so I can see if it's like mine? And if you could get back to me on the above on adding the filter to make sure the folder as a Job Status Value of Quoted.

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 (983)