Hello everyone,
Situation and goal is as follows:
Emails containing attachments are sent to an email address - there are 2 different emails, each with it's own different attachment for each PO - the names are generic and not helpful.
The goal is to save each attachment to a sharepoint, match the 2 files corresponding to the same PO and then send an email with both files as attachments;
Achieved so far:
- Attachments are being saved for each email to a specified Sharepoint folder
- AI models are used to extract relevant info from documents (i.e. order number and other identifiers)
- New files created in Sharepoint, file name being the order number extracted
Issues encountered:
- I don't seem to be able to loop the flow so that it waits until both files are saved and then move on to the next action - I am guessing I need to create a new flow ?
- I am unable to find a way to compare file names in Sharepoint and "match" together the files that contain the same value (i.e. 123.pdf and 000123.pdf)
Screenshots from my flow:



The way it works right now, since the 2 documents received in the 2 different emails are also different:
It saves the attachment to a sharepoint
Gets file content/metadata
Uses AI model to extract certain info that is found in one of the documents
If that succeeds (meaning the correct AI model was used for the correct file type) - it gets the email address from an excel table corresponding to that extracted info and then creates a file using the extracted data for the file name
If it fails (incorrect AI model used for the file type) - it uses another AI model to extract the info and creates a files using the extracted data for the file name
Not sure how to continue from here in order to achieve the main goal which is to send an automatic email to the address previously retrieved from the excel table with both files as attachments. I need to either loop the "on new email" trigger which doesn't seem to be possible, or create a new flow that checks the file names in the Sharepoint library and matches the ones that contain the same value.
In the current state, the flow will end after either of the AI models succeeds and 1 file is created, and then run again when another email is received.
Do you have any suggestions?