cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sam44
Level: Powered On

How to add item by using “Patch”? (how to grab SharePoint list item?)

I’m building PowerApps app with 2 screen.

As data source, I’m suing SharePoint list named “Events”. In this SharePoint list, I have 10 columns.

At screen1, I’m using Form control and wants users to enter value for column 1 to 5. Other columns such as 6 to 10 should be unselected, hide from form control.

I put SAVE button on screen1 so that user should save all input by “SubmitForm” function.

SAVE button also navigate user to move Screen2 and I put InputBox for column 6 to 10 and want to use “Patch” all user inputs to the same line of SharePoint list items.

Submitting form on screen1 is OK, surely created SharePoint list item but at the next screen 2, I cannot successfully grab same list item. How should I write “Patch” to add items on a same list item?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

Hi @Sam44,

 

Do you want to save your form data within the second screen into the same SP list item record the previous form submitted using Patch function?

 

I have made a test on my side, please take a try with the following workaround:1.JPG

 

2.JPG

 

 

Set the OnSelect property of the "Save" button within the first screen to following formula:

SubmitForm(Form1);Navigate(Screen2,ScreenTransition.Fade)

Note: The Form1 represents the Form control within the first screen.

 

Set the OnSelect property of the "Patch"  button within the second screen to following formula:

Patch(
    '20180907_case9',
    Form1.LastSubmit,
    {
        Status: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Id: 0,
            Value: DataCardValue10.Selected.Value
        },
        Department: DataCardValue11.Text
    }
)

On your side, you should type the following formula:

Patch(
Events,
Form1.LastSubmit,
{
Column6:DataCardValue6.Text,
Column7:DataCardValue7.Text,
...
Column10:DataCardValue10.Text
}
)

Note: The Form1 represents the Edit form within your first screen. 

 

The GIF screenshot as below:Test1.gif

 

 

 

More details about the Patch function in PowerApps, please check the following article:

Patch function

 

 

Best regards,

Kris

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.
5 REPLIES 5
Super User
Super User

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

@Sam44

 

This might be helpful - 

 

Patch( Events, Defaults( Events), Form1.Updates,Form2.Updates)

defaults function in the patch will create a new row/record and then updates from Form1 and Form2 will be patched


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sam44
Level: Powered On

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

@ThatAPIGuy

Thanks for your help!

I'm using Patch but my question is once user submmited Form1 on screen1 then move to screen 2 which only has "Inputbox", how I can update same line of record items since only I can get is Form1.LastSubmit.ID?

If I write like : Patch(Events, Defaults(Events), Column6:InputboxA_on the Screen2), this create "new" SharePoint list item.

How I can "Add" values in Inputbox to exsisting list item record is my question need to be solved.

 

Highlighted
Super User
Super User

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

Hi @Sam44,

 

in reality, you want the "edit" the record that you just created by patching in the text of your inbox.  The patch function is different for creating a new record vs. editing a record. On your first screen you are creating the new record so Defaults() is used for creating a new record in your data source.  For editing that record, you need to identify it for the Patch command in the second screen.. One way is to have the Patch(Events, Last(Events), {Column6:InputboxA_.Text}).  This will work if your Events table has 2000 records or less.  I personally prefer to use First(Sort(... in case the data source grows to more than 2000 items.

 

In your case, it would be Patch(Events, First(Sort(Events,ID,Descending)), {Column6:InputboxA_.Text})  // You would have this command in the OnSelect property of the button on your 2nd screen. 

 

Tip:  Check out the Patch() function information at https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

 

 

 

Community Support Team
Community Support Team

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

Hi @Sam44,

 

Do you want to save your form data within the second screen into the same SP list item record the previous form submitted using Patch function?

 

I have made a test on my side, please take a try with the following workaround:1.JPG

 

2.JPG

 

 

Set the OnSelect property of the "Save" button within the first screen to following formula:

SubmitForm(Form1);Navigate(Screen2,ScreenTransition.Fade)

Note: The Form1 represents the Form control within the first screen.

 

Set the OnSelect property of the "Patch"  button within the second screen to following formula:

Patch(
    '20180907_case9',
    Form1.LastSubmit,
    {
        Status: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Id: 0,
            Value: DataCardValue10.Selected.Value
        },
        Department: DataCardValue11.Text
    }
)

On your side, you should type the following formula:

Patch(
Events,
Form1.LastSubmit,
{
Column6:DataCardValue6.Text,
Column7:DataCardValue7.Text,
...
Column10:DataCardValue10.Text
}
)

Note: The Form1 represents the Edit form within your first screen. 

 

The GIF screenshot as below:Test1.gif

 

 

 

More details about the Patch function in PowerApps, please check the following article:

Patch function

 

 

Best regards,

Kris

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.
Sam44
Level: Powered On

Re: How to add item by using “Patch”? (how to grab SharePoint list item?)

Thanks @v-xida-msft !

Yes, I made it with your code!!

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 300 members 4,509 guests
Please welcome our newest community members: