cancel
Showing results for 
Search instead for 
Did you mean: 

Moving PowerApps Attachments to a Document Library

 

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.

 

Screen Shot 2018-04-21 at 12.10.07 PM.png

 

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.  

 

 

FlowAttachmentContentApplyEach.png

 

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. 

FlowCreateFileFilled.png

 

 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.

FlowUpdateFileProperties.png

 

 

 

 

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.

FlowDeleteAttachmentID.png

 

 

 

 

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. 

 

 

 

Comments

#scheduled for 5/2 @ 10:00AM (PST). Thanks!

Hi April

 

Am I correct in assuming that the Flow runs under the username of the person who created the Flow (The Flow Owner) ?

 

Thanks

 

Nigel

Hi April,

 

I've been able to follow the steps above to get everything to work - with the exception of the step to copy the file properties.  I've tried just about every combo to get it to work, but it errors out.

 

It copies over the attachment from my list to my doc library.  One thing I wasn't sure of was in the new doc library, did I need to set up the columns to be identical to the list?  I did that, but it didn't work, so I wasn't sure what to do there.  I tried converting them back to just text - no go. 

 

Like I said, the rest of it works, but getting the properties over with it, I'm just hitting a wall.  Any pointers would be most appreciated!

 

Thanks!

@NigelP - Yes you are correct, the Flow runs under the context of the person who created it.

 

@KelliWard0310 - Could you provide a screenshot or details on the error you are getting?  Usually, errors with updating file properties in SharePoint are from data type mismatch errors.  For example, you're trying to put a string into a Number field in SharePoint, etc.  

Hi April, I'm not @KellieWard0310, but I am hitting an error. I'll attach the screen shot.  Thanks so much for the clear directions!  I'm almost there! 

 

Here is the message that shows up in the "body" portion within "OUTPUTS".  

{
"error": {
"code": 502,
"source": "flow-apim-msmanaged-na-centralus-01.azure-apim.net",
"clientRequestId": "1d9252ce-45f0-4e95-941a-a2a3f8479939",
"message": "BadGateway",
"innerError": {
"status": 500,
"message": "Error converting value {null} to type 'System.Int64'. Path 'Id', line 2, position 13.\r\nclientRequestId: 1d9252ce-45f0-4e95-941a-a2a3f8479939\r\nserviceRequestId: dc91ad9e-c0ef-7000-725c-ad2ce43566df"
}
}
ProblemMovingFilesFromPowerAppsToSharePointDocLibrary.jpg

 

 

 

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • Solution Architect with Slalom, and organizer of the Boston Office 365 User Group, and long term SharePoint/Office 365 veteren. Find more at http://www.davidlozzi.com. Follow @DavidLozzi
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
>