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:
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:
- Loop through the Library (Apply to each)
- Set a variable to hold the Doc Ref No for each document as we loop through
- 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)
- Then another Apply to each that loops through the library again
- A Condition that looks for documents that have the same Doc Ref No
- 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)
- Then Send an email containing the value of the Links variable
Here's the Test Flow I've been working on

And here's the current output of the email:

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.