cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Saving attachments using Patch

I have a PowerApps App consisiting of 4 forms connecting to SharePoint list.  There are a number of  fields that are required on each form.

 

In my current (Add/Update) patch it is working great with the exception of my Attachments ( i dont know syntax).  I've seen responses here that say that attachments do not work with patch and you have to use SubmitForm(). Based on that, I put the attachment prompt on it's own form however, the "Next Screen" button executes a SubmitForm() for this form I get the error that other fields (that have been entered) are required.  I'm assuming because they have not yet been saved to the record in SharePoint and this individual SubmitForm() is attempting to save just the attachments.

 

Sooooo.... it would be realy nice if I could just add the syntax for saving these attachments within my already working Patch (add/update)

 

Another developer was excited that he found that he could put frmName.Updates in the Patch command. I tried that too.  he stated "I converted to this: GAForm.Updates;frmEnvironment.Updates "

 

Didn't work for me.

 

Does anyone know the syntax for Patching the attachment control data?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Anonymous ,

Do you want to patch the the attachments file from the Attachments control within your Edit form to your SP list?

 

If you want to patch the the attachments file from the Attachments control within your Edit form to your SP list individually using Patch function, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, you need to consider your Edit form data as a Whole, and type it within your Patch formula. I have made a test on my side, please take a try with the following workaround:5.JPG

Add a Button within your Edit screen, set the OnSelect property to following:

Patch('20190325_case13', Defaults('20190325_case13'), EditForm1.Updates)

On your side, you should type:

Patch('YourSPList', Defaults('YourSPList'), EditForm1.Updates)

In addition, if you want to update attachments file of an existing SP List Item, please take a try with the following formula:

Patch('YourSPList', BrowseGallery1.Selected, EditForm1.Updates)

More details about the Patch function, please check the following article for more details:

Patch function

 

Actually, you could consider use Patch function to patch data into your SP list instead of SubmitForm function. On your side, please set the OnSelect property of the "Submit"  button to following:

If(
   EditForm1.Mode = FormMode.New,
   Patch('YourSPList', Defaults('YourSPList'), EditForm1.Updates),
Patch('YourSPList', BrowseGallery1.Selected, EditForm1.Updates) )

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8

Hi @Anonymous ,

Adding attachments with Patch is still not possible.

I think you reference this threat https://powerusers.microsoft.com/t5/General-Discussion/Patch-Attachments/td-p/98121. The person in question solved the issue by creating the record with attachments by submitting the form and after that updating the record with Patch.

 

This scenario will only work in your case if you only want to add attachments when you create a record. You can still not add attachments on an excisting item using PowerApps. If this is something you need to do, you can consider using Flow for adding the attachments to your items. You can trigger the Flow on an action in your PowerApp.

I have found this blog describing how to add attachments to SharePoint items with Flow. I haven't tried this out myself yet. A comment on the blog: the writer of the blog uses the HTTP connector. I would advise you to use the Send an HTTP Request to SharePoint action that is part of the SharePoint connector instead. I think this action was not available yet when this blog was written. The HTTP connector is a premium connector and getting it to work in the context of SharePoint is a lot more work than using the advised action.

Anonymous
Not applicable

Thank you for the response. I didn't know Patch didn't support attachments.  My first attempt at PowerApps hasn't 
been the best. I can see the value in some areas and in others, not so much.

I thought about saving first.  Since I have multiple screens with required fields the issue is the Add has to include all of the required fields or it fails.  That was the reason I was using Patch - waited until the last SAVE and Patching all fields.  If I try to do a quick SubmitForm() on the form with the attachment before the Patch - errors due to empty required fields. 


I will tinker with this a bit more.  Worse case, I will default data into all of these fields before ths save, add the record and update the record on SAVE - if they cancel I'll have to delete it.

 

Also, the link we are both referring to - the poster actually said he was using Patch and that he was including FormName.Updates within his Patch and that solved the problem

I converted to this: GAForm.Updates;frmEnvironment.Updates - as I have multiple forms I can add in the update to them all with ; - I did not know I could use .Updates in Patch to do this 

I'll let you know what I end up doing.

v-xida-msft
Community Support
Community Support

Hi @Anonymous ,

Do you want to patch the the attachments file from the Attachments control within your Edit form to your SP list?

 

If you want to patch the the attachments file from the Attachments control within your Edit form to your SP list individually using Patch function, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, you need to consider your Edit form data as a Whole, and type it within your Patch formula. I have made a test on my side, please take a try with the following workaround:5.JPG

Add a Button within your Edit screen, set the OnSelect property to following:

Patch('20190325_case13', Defaults('20190325_case13'), EditForm1.Updates)

On your side, you should type:

Patch('YourSPList', Defaults('YourSPList'), EditForm1.Updates)

In addition, if you want to update attachments file of an existing SP List Item, please take a try with the following formula:

Patch('YourSPList', BrowseGallery1.Selected, EditForm1.Updates)

More details about the Patch function, please check the following article for more details:

Patch function

 

Actually, you could consider use Patch function to patch data into your SP list instead of SubmitForm function. On your side, please set the OnSelect property of the "Submit"  button to following:

If(
   EditForm1.Mode = FormMode.New,
   Patch('YourSPList', Defaults('YourSPList'), EditForm1.Updates),
Patch('YourSPList', BrowseGallery1.Selected, EditForm1.Updates) )

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amoncayo
Advocate I
Advocate I

Patch(source, record, FormName.Updates) 

Worked for me!!

Anonymous
Not applicable

I have what I want - I'm able to save attachments on ADD but not on Edit - I will live with that for now.  I need to spend more time reading and less time "attempting".   This community has been awesome.  I'll give back once I'm worthy  😉


@amoncayo wrote:

Patch(source, record, FormName.Updates) 

Worked for me!!


 

Hi there,

 

I am having the same problem that you were having. I have a number of edit screens and some of them have attachments. So I was trying to use Patch at the separate form to submit all the user input. I realize that only the last attachment is saved into the Sharepoint List and not all the attachments. I see you got the solution and saying you are using ADD. May I ask how you did that?

 

Thank you

This worked like a charm on one app. On another it is leaving certain fields blank in the SharePoint list. Any thoughts?

 

Bhanes22
Helper II
Helper II

this is by far the easiest way I've found to do this using power automate - https://youtu.be/yC0W5am6M3Q

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (1,906)