web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Saving attachment usin...
Power Apps
Answered

Saving attachment using Patch in a SP List

(0) ShareShare
ReportReport
Posted on by 146

Hello Experts!

 

I have a PowerApp which have an Edit Form connected to a SharePoint list. Within the SP list, there is a field named 'Letter Status' which is a  dropdown with the option: Sent, Pending and 'To be sent. Once the ' Letter Status' is changed to "To be sent", a Flow will start and will send an email to a specific person (specified in the SP List) with the attachment included (for that specific item). 

 

When the user entered the application, he/she needs to select a person from a Gallery, once selected the information will be displayed on the EditForm. Then, the user will need to attach a document in the field Attachments and once a document is attached, a button named "Send Letter" will be visible. When the button is pressed, it will automatically update the 'Letter Status' of that specific item to "To be sent" using Patch and the flow will starts. (I want to update the column 'Letter Status automatically once the button is pressed, not manually by the user).

 

Currently, the information is being updated correctly, however, the attachment is not being saved in the SP List.

My main challenge is to know how I can save the attached document in the SP List via the Patch function. Please find below the formulas used.

I have tried including the  EditForm.Updates within the expression, but I got an error. 

 

Visible property of the button "Send Letter":

If((CountRows(DataCardAttachment.Attachments))<1,false,true)

 

OnSelect property of the button "Send Letter":

Patch(
          'Data Source',
           {ID: Gallery1.Selected.ID},
           {'Letter Status':{
                  '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                  Value:"To be sent"}
          } 
)

 

 

Any suggestion is very much appreciated!! 🙂

Categories:
  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    Take a look at the following thread.  There is no way to save Attachments using Patch() other than as part of the entire form.  You can't save them individually.

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Saving-attachments-using-Patch/td-p/277984 

  • vsolanon Profile Picture
    146 on at

    Hi @Pstork1 Thank you for your response!

     

    Is it possible to combine both formulas inside the Patch - 1)EditForm.Updates to update the attachment file and 2) the below formula to automatically update the status of the "Letter Status" field once the button is pressed?

     

    PowerAppQuestion1.JPG

    I understand I would need to use the EditForm.Updated within the Patch but will also need to automatically update the value of the "Letter Status", is this something I can achieve?

     

    Thank you in advance,

  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    I don't think you can combine the edit form updates, which references a whole record, and the individual field update in the same Patch.  It would require two patch statements.

  • vsolanon Profile Picture
    146 on at

    @Pstork1  I am afraid the testing did not work as expected when I include two different Patch statements. I noticed it trigger two different flows:

    Please bear in mind the trigger of the flow is when an item is created or updated.

         1) First, it triggers a flow when the "Letter Status is updated to "To be sent" - which sends an email to the user. (which is correct, however, it does not include the letter since it is updated after 😞 )

         2) Then, it uploads the attachment in the SP List and triggers the flow. I have included a Condition in the Flow where it checks the "Letter Status" to be equal to "To be sent" in order to send a letter. In this case, no letter is sent (which is correct).

     

    Is it possible to make a rule where first the patch related to save the attachment is run and then the patch to update the "Letter Status"? 

  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    I'm not sure what you mean by "make a rule".  It is a known issue that updating a SharePoint list will trigger an Item Updated trigger.  The way I normally get around this is to add a condition to the trigger so it only fires when a status field is a specific value.

  • Verified answer
    v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @vsolanon 

    I think it is supported to combine 'Form.Updates' and a single record to the Patch function, they will be saved to the same record, please try this:

    Patch(
     'Data Source',
     {ID: Gallery1.Selected.ID},
     {'Letter Status':{
     '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
     Value:"To be sent"}
     },
     FormName.Updates
    )
     

    Test Result:

    Snipaste_2020-03-10_10-14-54.pngSnipaste_2020-03-10_10-13-19.png

    Sik

  • vsolanon Profile Picture
    146 on at

    Hi @v-siky-msft, thank you for your response!

     

    Kindly note I test he solution proposed but it did not update the value to "To be sent", it just upload the attachment.

     

    Is this possible to achieve?

    Thank you!

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @vsolanon ,

    Yes, I made a test again, the choices column and attachment can all be patched at the same time.

    Could you please share some steps and screenshots about how do you test that?

    Sik

  • vsolanon Profile Picture
    146 on at

    Hi @v-siky-msft 

    I include the below expression on the OnSelect of a buttonSave I have in the application.

     1) I select an employee from the Gallery1 and it displayed the information from the employee in an EditForm.

     2) I attached a document in the "attachment field" in the EditForm.

     3) Pressed the buttonSave. 

     4) Verify the column in the SP List

    The expression only updated the attachment document, but not change the value of the column.


    Patch(
    'STA Master Data',
    {ID: GalleryAttachLetter.Selected.ID},
    {'STA Letter Status':{
    '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    Value:"To be sent"}
    },
    EditFormSentLetter1.Updates
    )

     

    I also did a test including 2 buttons and adding one expression in each one of them. It did work, however, I was expected to do it in just one button 😞

    I am wondering if I am missing an step

     

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @vsolanon ,

     

    I just made a further test and can reproduce your issue if 'STA Letter Status' field is also added in EditFrom.

    Is that the same with your case?

     

    If 'STA Letter Status' field is also added in EditFrom, The Patch function contains two 'STA Letter Status' field value, which causes a conflict. 

    So please remove the 'STA Letter Status' Data Card in EditForm, the issue will fixed.

    Hope this helps.

    Sik

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard