Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Saving attachments using Patch

Like (0) ShareShare
ReportReport
Posted on 5 May 2019 17:09:22 by

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?

 

 

Categories:
  • zeyaul-hoda Profile Picture
    110 on 06 Jun 2024 at 07:11:21
    Re: Saving attachments using Patch

    I have the same issue I want to submit particular detail in data verse table and attachments in SharePoint\One Drive with unique ID to identify.

    Did you achieve that?

  • HEATFreight Profile Picture
    1,020 on 09 Dec 2022 at 00:30:07
    Re: Saving attachments using Patch

    Aha! I figured it out how to patch attachments from an item in one list to an item in a DIFFERENT list without using flow. If you need to patch attachments from an item in one SharePoint list to an item in a totally different SharePoint list, you must first remove the Attachments.Id parameter from the collection!

    I used the following code:

     

    ClearCollect(colAttachments,AddColumns(DropColumns(colAttachments,"Id"),"Id",""));
    ResetForm(AttachmentsForm);
    Patch(SharePointList,LookUp(SharePointList,ID=ThisItem.ID),AttachmentsForm.Updates);

     

  • Bhanes22 Profile Picture
    103 on 16 Aug 2022 at 20:14:04
    Re: Saving attachments using Patch

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

  • holland1994 Profile Picture
    11 on 14 May 2021 at 13:17:33
    Re: Saving attachments using Patch

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

     

  • Stevo1 Profile Picture
    2 on 06 Apr 2020 at 14:15:57
    Re: Saving attachments using Patch

    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

  • Community Power Platform Member Profile Picture
    on 08 May 2019 at 20:23:45
    Re: Saving attachments using Patch

    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!!


     

  • amoncayo Profile Picture
    36 on 07 May 2019 at 18:47:53
    Re: Saving attachments using Patch

    Patch(source, record, FormName.Updates) 

    Worked for me!!

  • Verified answer
    v-xida-msft Profile Picture
    on 07 May 2019 at 03:26:13
    Re: Saving attachments using Patch

    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 Power Platform Member Profile Picture
    on 06 May 2019 at 10:16:20
    Re: Saving attachments using Patch

    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.

  • Rebetcha Profile Picture
    645 on 06 May 2019 at 09:38:13
    Re: Saving attachments using Patch

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started
Loading started
Loading complete