I am posting this message to get help from you
I needed to move files from one library to another based on folder name, so I created a feed (see attached) . The flow works fine without errors. But the processing time is much too long because the library containing the folders has more than 2000 folders.
I would like to create an Excel table to optimise the processing time but I don't know how to do it.
Thank you for your help
I'm not sure that Excel would be of help to you here, @Bibi ...
Would I be right in assuming that you are looking to see if any of the folders listed have a name that either match es or contains a word that you have defined elsewhere?
If so, you can drastically cut down your flow using a Filter action and a boolean Variable action.
Don't take this too literally, I don't really know enough about your flow, because a lot of it is closed there.
So, I have run the List folder action as you have, and after which I run a Filter action to see only return items in the list that are folders, and where their name contains 'General'. Just remember this is an example, you might use a dynamic value instead of the word "General" here.
I use this expression by tapping on 'Edit in Advanced mode':
@and(equals(item()?['IsFolder'], true), contains(item()?['Name'], 'General'))
If I wanted that to look for an exact folder name, I would change 'contains' to 'equals'.
After that, I initialize (or 'set') my boolean doesExistVAR with:
This does two things to confirm if my folder exists:
Since I can't see the key steps, this might not be an exact fix for your troubles, but if you approach your data in a like minded way, you will likely get similar results. 🙂
I would like to thank you for answering me on this subject
I am sorry I did not put the key elements of the flow, so you will find attached the whole of my flow
I have tried your solution but it does not solve my optimization problem because my loop looks for folder by folder and that according to the number of folders in the list, unfortunately I have more than 2000 which slows down the processing time a lot
I think this is actually much easier, now, @Bibi ! 😅
Before I thought you needed to find a folder, but it is actually a file, and you have already defined where that is, so I think we can (together) simplify your flow by a lot! Give me some time, I'll sort something out. 👍
@Bibi a couple more questions:
Finally, a recommendation for your library data in your 'Email' library. For the Corps Du Mail column, you should not use 'body' from the email, you should use 'Body'. That is just the message text, then, rather than the whole email details. If you are already storing the whole email, it does not make sense to replicate it in the metadata.
If the answer to my first question is 'Yes' then you do not need to do this. If the creation fails, then the flow will fail, and you will be notified according to your notification preferences.
However, if you still want to be sure, then you can create 'Error reporting' using failure branches that use the 'Run after' settings for an action. You do this by:
This isn't a solution, just a helpful thing for complex flows. Try to play with it in test flows if you like.
Now, later on in the flow this is from I can check the number of errors, and if they are higher than 0 I know that this failed, and I can send myself a message to check in on the flow. 👍
Two Solutions !
One - Simple Flow (mostly)
This just finds the folder and makes the files. If there are any errors you rely on flow notifications to tell you.
Here it is spanned out:
This will hold the path to the client's folder.
emailSubjectCON is not strictly necessary, but it's just there because I wanted it. emailBody has the following expression, but obviously you should ensure your references are correct if you want to use this:
if(triggerOutputs()?['body/isHtml'], outputs('Html_to_text_on_the_email_Body')?['body'], triggerOutputs()?['body/body'])
Folder Management (folderChecker)
Inside the folderChecker scope I made Filter clientFolders which provides a list of folders that have the correct client number (clientNumCON). This results in this Filter action should 1 item if it exists, or 0 if it does not.
So, then there is Condition to see if the number of results in Filter clientFolders is equal to 1. To count the results in the filter the expression is:
If there is one result then the clientFolderVAR is set to the 'Full path' key from the first item  in the Filter clientFolders array with:
If there's zero results (because there can't be more) this branch will run, and will make the folder, then provide the clientFolderVAR with the 'Full Path' field from the Create new folder in clients library action.
Two - Error Tracking
I have updated this one to show the simplicity of the file creation logic.
This Error Tracking flow will only fail if a file creation fails, and you will have details of where it failed, too. You can then add more steps into the flow and track more errors if need be.
I'm sure you can see that there is more going on here.
Variables & Constants
First of all, here are the variables, there's the new clientFolderVAR and currently pointless folderOkVAR, plus there are also now integer counts for errors when making the files with clientLibraryErrVAR, emailLibraryErrVAR, and renamed totalErrorsVAR.
The constants are unchanged from the simple flow.
This expands on the simple version, except that I have realised that the folderOkVAR is utterly pointless at the moment, so you don't need that.
I have made this branched, with their own error counts to indicate more specific failures, I also added your fields (kind of 😉). Also, this now uses the new clientFolderVAR.
Finally, any error reporting is sent, or the flow finishes successfully.
Note - The only expression here is just adding the two variable counts together in the totalErrorsVAR.
Hello @eliotcole ,
I thank you very much for the time you give me, you are great
- I use "ListFolder" to list and retrieve the folders in a library
- The idea of the flow in general is to recover an email being in a library "Email" and to redirect it automatically towards the customer folder which corresponds to him according to the name of the email (the object of the email), for example if the object of the email sent is "toto - 73883 - abc", I get the second element which is 73883 and I look among the list of the folders the one which contains the number 73883 and I put it in
- The NuméroSAPObjet contains the following expression to retrieve the second element of the email subject:
- The NumeroSAPDossier contains the following expression to retrieve the second element of the folder name as well, as we have folders whose name is the client's name and a number:
- As explained before, in "ListFolders" I get the list of folders from a specific path:
Cheers, @Bibi! I will edit the solution above, just give me a few minutes.
Also, I think I have a couple of points to make, if you don't mind. 🙂
General Logic on Files
A quick note about a big part of your logic, more specifically you do not need to do this part: 🙂
recover an email being in a library "Email"
Because you have literally just created that file, you don't need to go get it. You can either just make another at the same time, or copy the file that you just made. 👍
Anyway, we still don't need to use the Apply to each, a Filter action will help here.
Client Identification / Separator in the Object (Subject)
It's a shame that you use the hyphen '-' as the separator, because this can be used a lot in the subject line which could affect handling this further down the line.
I think that there are two ways to handle this:
1. SharePoint List
If all of your clients have different email addresses, then you might be better off making a SharePoint list with 4 columns:
Then lookup the client number on the list, and use the Folder field.
2. Create a clients Library and Client Number Column
For now I think this option is a much better thing for you to do. Even if you do not want to create a separate 'clients' library you should definitely make a ClientNum column in the relevant SharePoint Libraries, as it will assist things in the future.
Anyway, if you have a clients library, then your folders are not restricted by the Shared Documents\general library settings, that might have other stuff going on. You can also then assign different privileges, add more columns, loads of stuff. It should not be too hard to just move all the client folders into a clients library.
OK, @Bibi, it should be good to go, now.
I guess the key thing is understanding that you can use a Filter action like a kind of merge of a Condition and an Apply to each.
Hello @eliotcole ,
Your solution seems to me much more useful and understandable.
However, there are two elements that are still confusing, I refer to the "continueEmailsLib" and the "continueClientsLib", what are they used for ? what is inside ?
Thank you so much
Hi, @Bibi , hehehe 😅 I actually think the 'Lib' part is a mistaken spelling of something else.
Anyway, if you look at one of my previous posts above you can see the meaning of them. They 'close' the error condition.
So, the 'continue' ones are just two normal Compose actions, however they have 'Run after' settings so that they will run even if the failure branch runs.
If you scroll up to this post, you will see where I quickly explained basic error handling in a flow.
Although, like I've said, you probably don't need it. I just saw that you were being super cautious about files being created and thought that I would offer that as a second option.
Hello @eliotcole ,
Your solution is really great, I thank you very much for the help you have given me
I have a small question: I did a test (see below), it worked but the rest of the flow was not realized, what should I do ?
Thank you in advance