cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
abd3127
Level 8

PowerApps:Updating a entry in sharepoint list

Hello, 

I am trying to update my existing entries into sharepoint list,but not able to do so.

Scenario:

1)I am having fields on screen 1 and screen 2 which are accepting info and then from screen 2 ,those are sent to sharepoint list . 

2) Now ,i am going to screen 3 where i am displaying the records in a gallery from the saved sharepoint list (same sp list in which i am saving data from screen 2).

3)Here i am selecting a entry in the gallery which i want to update .so i am naviagting back to screen 1 and populating fields there with the data from sharepoint list.

4) now after this,if i cahnge some values here on sccreen 1 or screen 2,i want to insert them in the same record in sharepoint list from which i am getting this original record (want to update the record).

i tried Update and Patch functions for so.

BUt while doing so if i try to add a new entry in sharepoint list,its not adding a new entry 

 

Patch(Sharepoint list,defaults(sharepointlist),{Values to be inserted in to list})

this is the function i am using for patching sharepoint lits .

How to update the same record without inserting a new record in list?

and 

What will be the condition for update if my whole record is going to update?

i mean the condition from  which update will identify which record to be modified.Help please!!! 

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: PowerApps:Updating a entry in sharepoint list

Hi @abd3127

All SharePoint lists have the ID column as their primary key, and this is all that is needed to uniquely identify a record.

Hence to update the Title column of the record with ID=7 in MySpList you would do this:

Patch(MySpList, {ID:7}, {Title: "My new title"})

Obviously the 7 and the title text can be changed to functions or variables.

 

PS You do not need to use the Defaults function, since this wastes time in a server call, just do this to create a new record:

Patch(MySpList, {ID: Blank()}, {Title: "My new record", OtherRequiredField: XX ...})

More on optimisation here:

https://baizini-it.com/blog/index.php/2017/09/13/powerapps-improving-app-performance/

12 REPLIES 12
abd3127
Level 8

Re: PowerApps:Updating a entry in sharepoint list

 
abd3127
Level 8

Re: PowerApps:Updating a entry in sharepoint list

I am not using forms here so how can i do it??

Meneghino
Level 10

Re: PowerApps:Updating a entry in sharepoint list

Hi @abd3127

All SharePoint lists have the ID column as their primary key, and this is all that is needed to uniquely identify a record.

Hence to update the Title column of the record with ID=7 in MySpList you would do this:

Patch(MySpList, {ID:7}, {Title: "My new title"})

Obviously the 7 and the title text can be changed to functions or variables.

 

PS You do not need to use the Defaults function, since this wastes time in a server call, just do this to create a new record:

Patch(MySpList, {ID: Blank()}, {Title: "My new record", OtherRequiredField: XX ...})

More on optimisation here:

https://baizini-it.com/blog/index.php/2017/09/13/powerapps-improving-app-performance/

LeifFrederiksen
Level: Powered On

Re: PowerApps:Updating a entry in sharepoint list

I use PowerApps to customize my list forms in Sharepoint.

I have an app with multiple screens that lay out the fields in a convinient way for the user.

 

Because of the multi-screen nature of the app, I use Patch instead of SubmitForm to write my data back to the list.

 

My problem is, that when I use Patch, the app does not close and the list is not automatically refreshed to show the new or edited item, like it does when I use SubmitForm.

 

How can I get the same UI behaviour when using Patch as when using SubmitForm?

 

Regards

Leif

/Leif
Meneghino
Level 10

Re: PowerApps:Updating a entry in sharepoint list

You can close the app with the Exit() function

LeifFrederiksen
Level: Powered On

Re: PowerApps:Updating a entry in sharepoint list

Using Exit() does not signal to Sharepoint to update the UI.

But RequestHide() did - using this solves the problem :-D

 

 

/Leif
Meneghino
Level 10

Re: PowerApps:Updating a entry in sharepoint list

What on earth is RequestHide()?  And why/how is it different from Exit()?  Why do we need both?

 

As usual there is no mention of this in the PowerApps documentation formulas page.

This is really frustrating...

I found mention RequestHide here:

https://docs.microsoft.com/en-us/powerapps/sharepoint-form-integration

 

Thanks @LeifFrederiksen for showing us something new.

 

Pity that PowerApps is so messy and the documentation so incomplete.

LeifFrederiksen
Level: Powered On

Re: PowerApps:Updating a entry in sharepoint list

Yes, lots of trial and error here...

 

After trying lots of complex stuff, my solution for a Sharepoint list form with multiple screens (tabs) was quite simple:

 

SharepointIntegration.onSave:

Patch(<List Name>;If(SharePointFormMode="New";Defaults(<List Name>);SharePointIntegration.Selected); <Form in tab 1>.Updates;<Form in tab 2>.Updates; <Form in tab 3>.Updates;<Form in tab 4>.Updates)
;;
RequestHide()

 

Note: I use ; as parameter delimiter and ;; for command delimiter instead of , and ; - this is probably due to some regional setting.

 

I probably should do some error handling - try/catch like structure on Patch? Anybody got experience in this area?

 

 

 

/Leif
Meneghino
Level 10

Re: PowerApps:Updating a entry in sharepoint list

Hi again @LeifFrederiksen

Error handling I do by collecting the result of the Patch in a collection or variable and then testing to see if the result is what is expected.  This is done like this pseudo code:

ClearCollect/Set(MyResult, Patch( etc. etc.));
If(Result = What I expect, OK, NOT OK)

Unfortunately this does not work with Remove since Remove/RemoveIf does not return the removed record(s) but the list without the removed records, and due to delegation not all the list