I'm trying to create a flow that goes item by item through a SharePoint list, find the files within a SharePoint document libary that contain the specific site name, and then emails those files to the contacts specified in the above list on a fixed schedule.
For example, the SharePoint list will have an entry where the Site Name = "Group ABC", with Contacts = "John Doe; Jane Doe". The Flow would loop through the list, hit that entry, then search the document library for any files that contain the string "Group ABC". Ideally, it would then package each of those files into a single email which gets sent to John Doe and Jane Doe. I'm not sure if that last part is possible, so if necessary, we can send 1 email per file.
The problem I'm having is that the straightforward way of creating this flow requires me to have nested loops. Top loop that cycles through the List, with a nested loop that then cycles through the Document Library for each list item. Flow does not currently support nested loops, but I feel like there has to be some workaround I could use that would allow this without creating nested loops. Just can't figure out how to structure it in a way that Flow allows.
I wasn't sure how you were triggering your first flow, so I went with a recurrence trigger and added a column so only the list items that haven't been checked are checked.
SharePoint List - contains the following columns
Flow runs every 5 mins, gets any rows from above list where [IsChecked] eq No (for example). Use an apply to each on the results returned. Insert [Site Name], [Contacts] into second list. Set [IsChecked] to Yes and [IsCheckedDate] to @utcnow().
SharePoint List 2
Flow is triggered when a new item is inserted into List 2. Gets files from Library when filename contains [Site Name] (from List 2). Use an apply to each on the results returned. Send an email with each file attached (I assume you can attach a file? I usually just send a link, but it sounds like you want the file(s) attached) to the people listed in the [Contacts] column. Once the apply to each has completed, you could update any additional columns in SharePoint List 2.
If you don't need the file attached, you could actually build a string with links to each file inside your apply to each loop, and after the apply to each has completed you could email out a single email to everyone and it would have a list of all the files and links to the files.
I think that will work...
Thanks for the reply. Flow will not let me write the Contacts field (Person or Group type) from one list to another. Initially I figured that Flow did not support multiple selections in this field (is that correct?), however, when I changed it to prevent multiple selections, I am still unable to write the contacts field.
It was my understanding that 'Person or Group' fields were now supported in Flow. Is this not the case?
I'm not aware of all the limitations of the Person/Group column types, but they have given me some headaches. What I've done in situations where people need to send multiple emails is have them enter in each email address as a semi-colon separated string, which can be used in the "To" field to send an email. It's not ideal, but it's a reasonable workaround for now.
We've updated and improved the layout and uploading format of the Power Automate Cookbook!
Fill out a quick form to claim your user group badge now!
We've given our badges an overhaul and also added some brand new ones!
Learn how to build the business apps that you need.
Find out where you can attend!
Watch & learn from the Power Automate Community Video Gallery!