Hello Flow Community!
I'd like to take a moment to introduce myself. My name is April Dunnam and I am partner and lead developer at a consulting firm in Tulsa, OK. I come from a SharePoint centric background so I've built a lot of SharePoint Designer Workflows in my day.
One of the newly released features of PowerApps is the ability to add attachments to a SharePoint list item. This is a great new feature but what if you'd rather have those documents saved in a document library instead of as attachments? Fortunately there is a way to accomplish this with Flow!
Background
Here's a little background on my use case and setup. I have a SharePoint list to track RFI's (Request for Information). I have customized this form with PowerApps and have added the ability to upload attachments to the RFI list item. I have a seperate SharePoint Document Library named Submittals that I want to move those attachments to. Ideally, I could copy over some metadta from my RFI like the Vendor Name, PO#, WO# and the RFI # to my document in the submittal and surface up those documents in my PowerApp.
How To Make it Happen
The first thing we've going to do is create a new blank Flow that will be triggered when an item is created in SharePoint. Next, we will add the "SharePoint - Get Attachments" Action. Insert the URL where your SharePoint list is and select the list from the dropdown . For the ID, select the ID from the When an item is created context in the Dynamic Content Window.
**Note: The ID doesn't show by default so you may have to click the "Show More" option in the top right hand corner.
Now that we have this set to trigger when an item is added and we are getting the attachments, the next step is to get the content from the attachments. We do this by inserting a "SharePoint - Get Attachment Content" Action. For the ID property you'll use the ID of the "when item is created" trigger. For the File Identifier property you'll select the ID from the "Get Attachments" action.
You'll notice after you fill out all of the properties for this action, that it automatically wraps the action in an "Apply to Each" function. So that means for each attachment that it finds in the previous action, it will get the properties for that attachment.
What We Have So Far:
Item Added to SharePoint via PowerApps --> Get all attachments on this item --> Loop through attachments and get attachment properties
Next, we need to use the "SharePoint - Create File" Action to add our attachment to the document library. The FileName is going to be the Display Name from our Get Attachments action. The File Content will be the Attachment Content property from our Get Attachment Content Action.
Optional Extra Steps
We could technically stop here if we wanted as we have accomplished the task of moving the attachments to a library. However, I want to copy over some of the metadata from my list item to the document including the associated RFI #, Vendor Name, etc. To do that, we are going to add the "SharePoint - Update File Properties" action. This will allow us to take metadata from our list and apply it to the document properties in our library.
The last optional thing that we can do here is to go back and remove the attachments from our list item so that we don't have duplicate files out there. To do this, we will add the "SharePoint - Delete Attachments" action. The ID will be the ID from the Update File Properties action and the File Identifier is the ID from the Get Attachments Action.
That's it! You now have a Flow that will get all of the attachements from your SharePoint based PowerApp and move those to a document library with metadata and delete the assocaited attachments.