Patching different Dataverse column types in Power Apps (Canvas Apps)
In this article, I want to explore PATCH function in Power Apps. The focus is to show you how we can use this function to update the different column types in Dataverse.
The column type that I will cover in this article includes number, text, DateTime, boolean, single-select choice, multi-select choice, LookUp & Image.
I created a Players table which contains the below mentioned columns:
To show the patching method for lookup columns, I created a Country table which had the name of the countries as a choice column which is then used in the Players table.
Now it's time to put some dummy data to explore the patch functionality. And let stress this again this is DUMMY data.
I am creating a form to add fresh players to the database.
Now I want to cover two types of PATCH. One is when we add a fresh player to Dataverse, and the other is when we want to edit an existing player in Dataverse.
If you want to know what a Patch function does or what is the syntax of it, then please refer to the exhaustive documentation from Microsoft below:
领英推荐
Create a New Record
Code:
The Defaults(Players) is used when we are creating a new record. We then pass all our values as a record to the table.
Edit an existing Record
When we select an existing record, we want the form to populate with their respective values. Here is where sometimes it can get confusing on which property of the control to update, as in some cases you update the Default property and in other cases you update the DefaultSelectedItems.
When I select an Item from the gallery, I then store that item in a variable (varSelectedItem).
Now that we have populated the fields with data from the selected item. Let us now focus on updating this record using the PATCH. And the surprising thing is that the code almost remains the same with Create a record. In creating records, we used Defaults, but here we use the varSelectedItem as that is the record, we want to make the changes to.
Code:
Conclusion
This article we discussed about how we can use the Patch function to create/modify records that has different type of columns in the Dataverse.
Powerbouwer | Microsoft Business Applications MVP | PowerAddictsNL | Power Platform Challenge
1 年Federico Porrazzo handige uitleg over patch forms