cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
overheadpress18
Advocate I
Advocate I

Connect and update Sharepoint list with PowerApps form

On the left of the picture I have a form in my PowerApps connected to the SharePoint list on the right. How can I connect the two so that if the name in my PowerApps matches the name in the SharePoint list the items will correspond to the values in the SharePoint? For example, right now the name should match between the two so item 1, item 2 and item 3 should be toggled automatically in my PowerApps because it is checked in the SharePoint. 

 

Right now if I click submit in my PowerApps it would just create a new record in my SharePoint regardless if the name matches or not. I would like it to create a new record in my SharePoint if the name doesn't match in PowerApps. Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions

@overheadpress18 

 

Inside the optional third argument of the Patch itself. And this whole Patch goes in the OnSelect of your "Submit" Button:

 

Patch( DataSource, BaseRecord, With({_myRecord : LookUp(YourNameColumn = User().FullName}),If(!IsBlank(_myRecord),_myRecord, Blank())))

 

 The above essentially makes the Patch conditional between two versions. If the LookUp record exists, it will use it as the record to Patch. Otherwise, it will not use any record to Patch, which calls the version of Patch which creates a new Record.

 

Check if it helps.

 

----------------------------------------------------------------------------------------

EDIT: While the above exactly as it was had been accepted as solution, in case someone that comes across this has trouble when trying the above, it is possible you might need to do it more like the following instead.

I did not test either version, and both versions are for initial guidance only, here is the version that I believe might be more correct though:

 

From my solution Font size and weight custom settings 

 

You can do this kind of create new item or edit existing item using e.g. Patch function

Patch( DataSource, BaseRecord, ChangeRecord1)

 In the above, if BaseRecord is Defaults(), the Patch will create a new item instead. If BaseRecord is an existing Record instead, the Patch will instead modify that existing record. So same formula above can do both things based on what the value of BaseRecord above is. 

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch#modify-or-crea...

Modify or create a record in a data source

Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])

  • DataSource – Required. The data source that contains the record that you want to modify or will contain the record that you want to create.
  • BaseRecord – Required. The record to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.
  • ChangeRecord(s) – Required. One or more records that contain properties to modify in the BaseRecord. Change records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

 

-----------------------

 

In other words, if the solution as I have it didn't  work, then:

1. Actually the solution I gave it might be pretty close. The 3rd argument might need to be almost duplicated again for the 2nd argument as a conditional too, except this time using Defaults() instead of Blank() for the case of a record not existing, and making sure to be using the original record as is without modification for the record to modify.

2. Also, the 3rd argument as originally given, might need to be slightly adjusted to have the actual changed record you want to perform (not the existing record - because the existing record belongs in the 2nd argument). The use of Blank() as originally given, in the case of the record not existing - this might actually be fine.

3. Putting an outer With at the very beginning of the Formula may help reduce duplication of statements in the formula that might occur if doing the above.

 

 

 

 

View solution in original post

10 REPLIES 10
poweractivate
Community Champion
Community Champion

 

Patch( DataSource, BaseRecord, If(!IsBlank(LookUp(Something)), RecordToEdit, Blank()))

 

Check above as an initial guidance, you will need to put values that make sense where appropriate.

Thanks for the response, I am new to PowerApps which property would I put this in? 

@overheadpress18 

 

OnSelect of the button.

 

The formula will not work as is, you need to put values in there that make sense. I only provided it as initial guidance, the actual values to put in there for things like DataSource, BaseRecord, Something, and RecordToEdit depend on your scenario. 

If I understand correctly placing it into my submit button will submit the changes, but what if I want the default property of the form to display what is currently on the sharepoint list if the names match? For example right now items 1-3 should be checked by default in the powerapps. Thanks again!

@overheadpress18 

 

If you want to edit an existing record instead of creating a new record, you must use it this way:

 

 

Patch( DataSource, BaseRecord, LookUp(Title = "SomethingYouWant"))

 

That way, it will not create a new record, but update an existing one. The part saying Title = "SomethingYouWant" can instead be any filtering criteria you need. DataSource and BaseRecord also need to be values making sense for you.

 

Check if it helps.

How about for default view of the form before any button is clicked? Because the name in the powerapps will change according to who is using the app, and I want it so that if the user's name is already in the sharepoint then the powerapps will display the data accordingly before making any changes.

@overheadpress18 

 

Ah do you mean you are already using (or want to use) a formula to get the current user of the PowerApp and use it as a criteria for the LookUp?

 

 

 

User().FullName

 

 

 

to get the current person using the app? If so, that might be also a good fit for the LookUp(Title = "SomethingYouWant") part, so it might be something like LookUp(YourNameColumn = User().FullName)

 

If you did want to create a new record if there was none matching the criteria, then you could combine this approach here with the "If" in my first response, to indeed still create a new record if there was not an existing one already.

 

 

 

(see most recent reply for example) 

 

See if it helps further.

 

Thank you! yes I am currently using User.FullName and I will try what you suggested. Under which property of my form would I input LookUp(YourNameColumn = User().FullName)? Or is it elsewhere instead of my forms? 

@overheadpress18 

 

Inside the optional third argument of the Patch itself. And this whole Patch goes in the OnSelect of your "Submit" Button:

 

Patch( DataSource, BaseRecord, With({_myRecord : LookUp(YourNameColumn = User().FullName}),If(!IsBlank(_myRecord),_myRecord, Blank())))

 

 The above essentially makes the Patch conditional between two versions. If the LookUp record exists, it will use it as the record to Patch. Otherwise, it will not use any record to Patch, which calls the version of Patch which creates a new Record.

 

Check if it helps.

 

----------------------------------------------------------------------------------------

EDIT: While the above exactly as it was had been accepted as solution, in case someone that comes across this has trouble when trying the above, it is possible you might need to do it more like the following instead.

I did not test either version, and both versions are for initial guidance only, here is the version that I believe might be more correct though:

 

From my solution Font size and weight custom settings 

 

You can do this kind of create new item or edit existing item using e.g. Patch function

Patch( DataSource, BaseRecord, ChangeRecord1)

 In the above, if BaseRecord is Defaults(), the Patch will create a new item instead. If BaseRecord is an existing Record instead, the Patch will instead modify that existing record. So same formula above can do both things based on what the value of BaseRecord above is. 

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch#modify-or-crea...

Modify or create a record in a data source

Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])

  • DataSource – Required. The data source that contains the record that you want to modify or will contain the record that you want to create.
  • BaseRecord – Required. The record to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.
  • ChangeRecord(s) – Required. One or more records that contain properties to modify in the BaseRecord. Change records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

 

-----------------------

 

In other words, if the solution as I have it didn't  work, then:

1. Actually the solution I gave it might be pretty close. The 3rd argument might need to be almost duplicated again for the 2nd argument as a conditional too, except this time using Defaults() instead of Blank() for the case of a record not existing, and making sure to be using the original record as is without modification for the record to modify.

2. Also, the 3rd argument as originally given, might need to be slightly adjusted to have the actual changed record you want to perform (not the existing record - because the existing record belongs in the 2nd argument). The use of Blank() as originally given, in the case of the record not existing - this might actually be fine.

3. Putting an outer With at the very beginning of the Formula may help reduce duplication of statements in the formula that might occur if doing the above.

 

 

 

 

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,414)