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

How to check if a folder exists in SharePoint Document Library from a excel list

Hello everyone.

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.

 

merge_from_ofoct.png

 

Thank you for your help

11 REPLIES 11
eliotcole
Super User
Super User

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'.

basicBits.jpg

 

After that, I initialize (or 'set') my boolean doesExistVAR with:

greater(length(body('Filter_array')), 0)

This does two things to confirm if my folder exists:

  1. length() - This counts the amount of items that the filter returns.
  2. greater() - This returns a true value if the length() is greater than 0.

 

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. 🙂

Hello @eliotcole 

 

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 lot2021-11-08 17_40_56-Edit your flow _ Power Automate.png2021-11-08 17_42_09-Edit your flow _ Power Automate.png2021_11_08_17_42_23_Edit_your_flow_Power_Automate.png2021_11_08_17_44_14_Edit_your_flow_Power_Automate.png2021_11_08_17_45_23_Edit_your_flow_Power_Automate.png2021_11_08_17_46_28_Edit_your_flow_Power_Automate.png

 

eliotcole
Super User
Super User

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. 👍

eliotcole
Super User
Super User

@Bibi a couple more questions:

  1. Are you using the List folder action to ensure that the file has been made correctly?
  2. Are you then copying the same email to a client folder?
  3. Is NumeroSapObjet counting the amount of characters in the subject of the email? Or is it the size of the file that it has created?
  4. Similarly, is NumeroSapDossier counting the amount of characters in the subject of the document file that you create?
  5. Actually if you could copy these expressions here, that would be useful:
    1. In NumeroSapObjet the trim() expression.
    2. In List folder, the encodeUriComponent() expression.
    3. In NumeroSapDossier the trim() expression.

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:

  1. Create a parallel branch with an an action inside it (I usually increment an integer variable).
  2. Go to the action '...' menu and select 'Configure run after'.
    runAfter01.jpg

     

  3. Check only the 'Has failed' option and tap 'Done'.
  4. Now join your branches with an action.
  5. This must run whatever happens in both branches. So;
    1. ... tap 'Configure run after' once, marking all the options, then tap 'Done',
    2. ... then tap 'Configure run after' again, but select the other action on the left, then mark all the options, and tap 'Done'.

runAfter02.jpg

 

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. 👍

eliotcole
Super User
Super User

Two Solutions !

One - Simple Flow (mostly)

simpleIshFlow-minimised.jpg

 

 

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:

simpleIshFlow.jpg

Variable clientFolderVAR

This will hold the path to the client's folder.

 

Constants

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'])

 

fullFlow03-Constants.jpg

Note:

  1. There is an HTML to Text on the email message/Body? This way it means that the column in the libraries will not be full of HTML if the trigger field 'isHtml' equals true.
  2. I should have named the emailBody constant 'emailBodyCON' for continuity.

 

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:

 

 

length(body('Filter_clientFolders'))

 

 

Yes branch

If there is one result then the clientFolderVAR is set to the 'Full path' key from the first item [0] in the Filter clientFolders array with:

body('Filter_clientFolders')[0]?['Path']

No branch

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. 

fullFlow01-Complex.jpg

 

 

More detail

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.

fullFlow02-Variables.jpg

 

The constants are unchanged from the simple flow.

 

Folder Management

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.

 

fullFlow04-FolderChecker.jpg

 

 

 

File Creation

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.

fullFlow05-AddFiles.jpg

  • Title is the outputs of emailSubjectCON.
  • clientNum is the outputs of clientNumCON.
  • emailBody is the outputs of emailBody.

 

Error Reporting

Finally, any error reporting is sent, or the flow finishes successfully.

fullFlow06-EndingFairy.jpg

Note - The only expression here is just adding the two variable counts together in the totalErrorsVAR.

expression

 

 

 

add(variables('emailLibraryErrVAR'), variables('clientLibraryErrVAR'))

 

 

 

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:
trim(split(outputs('OBJECT'), '-')[1])

 

- 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:
trim(split(outputs('Compose'), '-')[1])

 

- As explained before, in "ListFolders" I get the list of folders from a specific path:
encodeUriComponent('/Shared Documents/Clients/')

eliotcole
Super User
Super User

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:

  1. Email
  2. Client
  3. ClientNum
  4. Folder

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.

eliotcole
Super User
Super User

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

eliotcole
Super User
Super User

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 ?

 

2021-11-14 01_11_50-Run History _ Power Automate.png

 

Thank you in advance

Helpful resources

Announcements

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!   Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪 🌠  

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

March User Group Update: New Groups and Upcoming Events!

  Welcome to this month’s celebration of our Community User Groups and exciting User Group events. We’re thrilled to introduce some brand-new user groups that have recently joined our vibrant community. Plus, we’ve got a lineup of engaging events you won’t want to miss. Let’s jump right in: New User Groups   Sacramento Power Platform GroupANZ Power Platform COE User GroupPower Platform MongoliaPower Platform User Group OmanPower Platform User Group Delta StateMid Michigan Power Platform Upcoming Events  DUG4MFG - Quarterly Meetup - Microsoft Demand PlanningDate: 19 Mar 2024 | 10:30 AM to 12:30 PM Central America Standard TimeDescription: Dive into the world of manufacturing with a focus on Demand Planning. Learn from industry experts and share your insights. Dynamics User Group HoustonDate: 07 Mar 2024 | 11:00 AM to 01:00 PM Central America Standard TimeDescription: Houston, get ready for an immersive session on Dynamics 365 and the Power Platform. Connect with fellow professionals and expand your knowledge. Reading Dynamics 365 & Power Platform User Group (Q1)Date: 05 Mar 2024 | 06:00 PM to 09:00 PM GMT Standard TimeDescription: Join our virtual meetup for insightful discussions, demos, and community updates. Let’s kick off Q1 with a bang! Leaders, Create Your Events!  Leaders of existing User Groups, don’t forget to create your events within the Community platform. By doing so, you’ll enable us to share them in future posts and newsletters. Let’s spread the word and make these gatherings even more impactful! Stay tuned for more updates, inspiring stories, and collaborative opportunities from and for our Community User Groups.   P.S. Have an event or success story to share? Reach out to us – we’d love to feature you!

Users online (6,158)