Patching different Dataverse column types in Power Apps (Canvas Apps)

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.

No alt text provided for this image

I created a Players table which contains the below mentioned columns:

  • Player Name (Column type: Text)
  • League (Column type: Single-select choice)
  • Date Joined (Column type: Date Time)
  • Country (Column type: LookUp choice)
  • Contract Length (Column type: Number)
  • Sponsors: (Column type: Multi-select choice)
  • International: (Column type: Boolean)
  • Player Image: (Column type: Image)

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.

No alt text provided for this image
DUMMY Data Gallery

I am creating a form to add fresh players to the database.

No alt text provided for this image

  • Player Name: Format(property): TextFormat.Text
  • League: Items(property): Choices('League Choice')
  • Country: Items(property): Choices([@Countries].'tst_country')
  • Contract Length: Format(property): TextFormat.Number
  • Sponsors: Items(property): Choices(UpdatedSponsors)

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:

No alt text provided for this image

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).

  • Player Name (Text): Default: varSelectedItem.Name
  • League (Single-select Choice): Default: varSelectedItem.League
  • Date Joined (Date): DefaultDate: varSelectedItem.'League Join Date'
  • Country (LookUp Choice): DefaultSelectedItems: {Value: varSelectedItem.'Player Country'.'Country (tst_country)'}
  • Contract Length (Number): Default: varSelectedItem.'Contract Length'
  • Sponsors (Multi-select Choice): DefaultSelectedItems: varSelectedItem.Sponsors
  • International (Boolean): Default: varSelectedItem.'International Status'
  • Player Image (Image): Image: varSelectedItem.'Player Image'.Full

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:

No alt text provided for this image

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.

Miguel Verweij

Powerbouwer | Microsoft Business Applications MVP | PowerAddictsNL | Power Platform Challenge

1 年

Federico Porrazzo handige uitleg over patch forms

要查看或添加评论,请登录

Ashwin Ganesh Kumar的更多文章

  • Bulk Deletion in Dataverse: A Beginner's Guide

    Bulk Deletion in Dataverse: A Beginner's Guide

    We recently encountered a challenge with Dataverse capacity on the client side. One way to overcome this issue is to…

  • Column-Level Security- What is that?

    Column-Level Security- What is that?

    If you are new to working on projects with Dataverse, this could be a bit overwhelming. But don't worry, we will figure…

    11 条评论
  • Build in-app notification for model driven apps

    Build in-app notification for model driven apps

    For this week, I want to explore the possibility of building in-app notification for a model driven app. But how? We…

    2 条评论
  • Power Apps Monitor

    Power Apps Monitor

    Have you encountered a situation where the app that you have developed is slow or has some issues? Or have you been in…

    1 条评论
  • Virtual Table Creation Wizard

    Virtual Table Creation Wizard

    What are virtual tables? It is a custom table in Microsoft Dataverse that contains data from an external data source…

    1 条评论
  • Review: CoE Starter Kit December release

    Review: CoE Starter Kit December release

    I think a lot of us have already installed CoE Starter Kit and are using it daily for different purposes like admin…

    2 条评论
  • Review: Security Risk Assessment and Management

    Review: Security Risk Assessment and Management

    I recently came across a LinkedIn post about Security Risk assessment app. As I haven't tried the previous version of…

    4 条评论
  • Review: Power Platform Adoption Assessment

    Review: Power Platform Adoption Assessment

    What is it? It is a tool to help customers run through a set of questions based on their interests. The tool then gives…

    5 条评论

社区洞察

其他会员也浏览了