
We receive invoices into our outlook. I want to create a flow of when an email is received with in invoice, the attachment is saved to a SharePoint folder based on the email sender.
I have a vendor folder in SharePoint, and within the folder, there is a folder setup for each vendor and then that goes to sub-folders for each year and month.
Example Folder:
I'm thinking of having an excel table setup with the vendor folder name in one column and the email address for those vendors in another column. The flow would read off the table to see which folder is associated with that email address and save the file in that folder based off the table.
I would then need it to go into the correct year and then the current month that the email is received and save it in there.
File name = invoice# - mm-dd-yyyy (attachment received date)
Any ideas on how to set this flow up or better ways to accomplish this?
Hi @georgemaka ,
Give this a go.
1) Use a when a new email arrives trigger and ensure you tick include attachments. I also initialized a variable to show you the outputs.
2) Loop through each attachment. You may also want to add a condition to exclude attachments which are not your invoices e.g. email signature images etc. You can use Attachment Content Type to determine this.
3) I used SharePoint and added a Get Items. Use a filter to filter based on the the Title column
4) I've set the FilePath variable and added a compose to show you the output. The formula you need is below. Swap out the value in bold with your document library name.
/document library name/@{items('Apply_to_each_2')?['Folder']}/@{formatDateTime(utcNow(),'yyyy')}/@{concat(if(equals(length(string(int(formatDateTime(addDays(utcNow(),90), 'MM')))),1),concat('0',int(formatDateTime(addDays(utcNow(),90), 'MM'))),int(formatDateTime(addDays(utcNow(),90), 'MM'))), '-', formatDateTime(utcNow(),'yyyy'))}
And the outputs
As mentioned, you need should add a condition to exclude email signature images and also add some logic to create your filename. However, the above should get you 99% of the way there. Your filename should use a concat() and @{formatDateTime(triggerOutputs()?['body/receivedDateTime'],'MM-dd-yyyy')} to get the received date in your date format.
--------------------------------------------------------------------------
If I have answered your question, please mark my post as a solution
If you have found my response helpful, please give it a thumbs up
Connect on LinkedIn