cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerapps890
Post Prodigy
Post Prodigy

Patch attachment to sharepoint

How can I allow the user to add attachments and submit it to a sharepoint list. This is my current patch statement for the data cards. SubmitForm(Form1);NewForm(Form1);Patch('CPQ Comment', Defaults('CPQ Comment'), {Title: DataCardValue3.Text, Comment: TextInput2.Text, Name_:Label6.Text, Date:Label7.Text}); Navigate(BrowseScreen1,Fade); Reset(TextInput2) 

powerapps890_0-1596648129940.png

I copied and pasted the attachment card from the edit form.

22 REPLIES 22
mdevaney
Community Champion
Community Champion

@powerapps890 

Attachments may not inserted using the PATCH function.

You must use SUBMITFORM to do it instead.  There are not any workarounds to do it inside of PATCH.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

How do i submit the form to the data source using that then? @mdevaney 

@powerapps890 
The typical pattern is to insert a new row using PATCH and then SUBMITFORM.

// Insert new row in the datasource
Set(currentRecord,
    Patch(
        'CPQ Comment',
        Defaults('CPQ Comment'),
        {
            Title: DataCardValue3.Text,
            Comment: TextInput2.Text,
            Name_:Label6.Text, 
            Date:Label7.Text
        }
    )
);

// Submit the attachment in the form
SubmitForm(Form1);
NewForm(Form1);
Reset(TextInput2) 

 
Make sure you have this code inside the Item property of the Form.

currentRecord

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

so that whole thing goes in the button? I don't understand how the attachment is being submitted because the new column I created in the data source is not being called. Also, it is saying currentrecord is not compatible with my data source. @mdevaney 

@powerapps890 
Yup, the whole thing goes in the button.  CurrentRecord must be from the same datasource as the Form or else an error will be raised.

Is the variable for PATCH at least returning a value?

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

 

v-bofeng-msft
Community Support
Community Support

Hi @powerapps890 :

In theory, using form control and submitform function is the only way to add attachments to existing records.

If you insist on using Patch function,you could consider take a try to only add the Attachments field within the form control.

I have made a test on my side:

1\Add an edit form(Form1)

DataSource

 

List3 /List3 is my data source/

 

DefaultMode

 

FormMode.New

 

2\Add a button 

OnSelect:

Patch(
    List3,
    Defaults(List3),
    {Title: 1},
    Form1.Updates
)

On your side, you should type following formula:

Patch(
        'CPQ Comment',
        Defaults('CPQ Comment'),
        {Title: DataCardValue3.Text, Comment: TextInput2.Text, Name_:Label6.Text, Date:Label7.Text}
, Form1.Updates )

Note: The Form1 represents the Edit form control within your app, which only display the Attachments field. 

I think these links will help you a lot:

https://powerusers.microsoft.com/t5/Building-Power-Apps/Need-to-add-Attachment-to-a-PATCH-to-a-Share...

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

Best Rergards,

Bof

Currently I have editform1 which contains the attachment within detail form1. Can I do it this way? Maybe it does not need a patch function? I am just really not sure how to submit it to the sharepoint list with the other items without a button and patch. @v-bofeng-msft 

Where does the attachment go. Like if the column is called attachment where does that form go?

Hi @powerapps890 :

Sorry, I did not understand what you mean, could you describe it in detail?

Best Regards,

Bof

Helpful resources

Top Solution Authors
Top Kudoed Authors
Users online (3,303)