cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AlanMcK
Helper I
Helper I

Compile links to related documents stored in a SharePoint Library

I'm having a bit of a headache, battling with the logic in a Power Automate Flow.

I have a document library where the documents are named in this format:

  • A001 - Debt and Cash Allocation.docx

Then there are supporting documents that have a similar format, eg:

  • A001 - Debt and Cash Allocation - Outward Reporting
  • A001 - Debt and Cash Allocation.pdf
  • A001 - Debt and Cash Allocation - KPIs

There's an additional column that also holds the Document Reference number, eg:

  • A001

What I want to do is ... when the main document is due for review, the Flow sends out an email to the Owner (I've nailed that bit), I also need to include (in the email) links to all the supporting documents in the Library as well.

What I've tried to do is:

  1. Loop through the Library (Apply to each)
  2. Set a variable to hold the Doc Ref No for each document as we loop through
  3. Set another variable to hold the document links, but set the value to Null (to clean up the variable after each loop of the next stage)
  4. Then another Apply to each that loops through the library again
    1. A Condition that looks for documents that have the same Doc Ref No
    2. If they do, then Append to string variable with the link to the FileName from the first Apply to each (this might be where it's going wrong)
  5. Then Send an email containing the value of the Links variable

Here's the Test Flow I've been working on

 

pic01_Get-supporting-docs.jpg

And here's the current output of the email:

 

pic02_Email-output.JPG

 

The Append to string variable action just seems to add the same document 11 (the number of documents being scanned by the first Apply to each) times.

I'm probably missing something really obvious, but any help would be gratefully accepted.

 

3 REPLIES 3
ivan_apps
Memorable Member
Memorable Member

Perhaps I'm not understanding correctly but you're looking to email links to all documents in a library that have a certain Reference Number. You have that reference number in a separate column already, couldn't you just query the document library for that reference number instead of looping through each item? Your filter criteria would be "DocumentReferenceNumber eq '[your ref number]'" and it would get everything you need.

 

If I'm misunderstanding the question let me know. But it seems like you're looping and comparing a reference number where you might be able to avoid a loop altogether.

---------
If I helped you solve your issue, please mark it as a solution or give it a like!

I wish it were that simple  🙂

 

Every week, the Flow scans the library for documents that have a review date in a certain time-window (eg, 90 days from now). There will be more that one document falls in that window. So I already have to loop through the library to find docs with that review date (90 days from now). That bit I have working fine, so it's not included in my screengrab above.

But my colleagues then decided that they wanted an additional feature. For each main document tagged with, say, "A001" there are several supporting docs, also tagged with the value "A001" and they wanted me to include links to the supporting docs in the notification email (you can see why I had little luck finding a solution via Google). Then the Flow needs to look at the next document that falls inside the time-window, say "A002" and then include links to the A002 supporting docs in that notification, and so on ...

 

I can't just hard-code the time-window and the DocRefNo into the first condition, because there are many main documents the Flow needs to identify during a run ...

 

Does that help?

Yes ok I understand a little bit more now. However I think ‘scanning’ the library is probably still going to cause you issues, particularly performance related because you are essentially looping through the library, and then for every item looping through the entire library again. In programming languages you generally try to avoid ‘table scans’ as they are expensive operations that and you are doing basically a n^n table scan.

 

lets say you have the following document library structure:

 

Name | Doc Reference # | Review Date

 

Requirement #1- Get all Documents with a Review Date 90 days from Today.

—> Create a scheduled flow that runs every day at whatever hour you’d like. Query your document library with the following criteria (syntax may not be 100%):

ReviewDate eq “addDays(utcNow(), 90, ‘yyyy-MM-dd’)”


Since this flows runs every day, this should give you the exact number of Files that have a Review date in exactly 90 days from today. We avoid 1 table scan by doing this. 

Requirement #2- for all those documents from #1 retrieve all associated files by Reference Number (regardless of review date). 

From our returned documents in #1, we will loop through each one and query the same document library for matching DocRef numbers. Filter criteria:

 

DocumentReferenceNum eq “currentItem.DocumentReferenceNum”

 

Loop through the results and create your table of links like you did before. Exit the inner loop and then send the email referencing the outer loop’s Document Name and Review Date.

 

Hopefully that makes sense!

---------
If I helped you solve your issue, please mark it as a solution or give it a like!

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,748)