web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Compile links to relat...
Power Automate
Unanswered

Compile links to related documents stored in a SharePoint Library

(0) ShareShare
ReportReport
Posted on by 68

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.

 

Categories:
I have the same question (0)
  • ivan_apps Profile Picture
    2,187 Moderator on at

    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.

  • AlanMcK Profile Picture
    68 on at

    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?

  • ivan_apps Profile Picture
    2,187 Moderator on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard