How to Use the Dataverse Patch Function?

Introduction

The PowerApps Patch function in Dataverse is a helpful tool that allows you to update or add data to tables. It's a way to tell your app to change information in specific places, like updating names or adding new records. This function works well with Dataverse, which is where your data is stored. It's like giving your app the power to fix and update things in your data storage.

Employees Table

Within the context of this exploration, let us consider the 'Employees' table, a fundamental component of many business databases. The table comprises a range of columns, each designed to hold specific types of information. The column types encompass AutoNumber, Single Line of Text, Date and Time, Email, Choice, Currency, Multiple Lines of Text, Image, Lookup, Multi-Select Option Set, and File. Such a varied collection of column types exemplifies the complexity that developers often encounter when managing data.

Thus, our table will appear as shown below.

Column Name Data Type
Name Text
Birthdate Date only
Department Choice (HR, IT, Finance)
Salary Currency
Notes Multiple Lines of Text
ProfileImage Image
Resume File
Manager Lookup (AAD user)
Skills Multi-Select Option Set


Create a canvas application

To show how the Dataverse Patch function works, let's start by making a digital tool using Microsoft PowerApps. Here's how we do it:

  • Open PowerApps.
  • Click on 'Create.'
  • Pick 'Blank app.'
  • Choose 'Blank canvas app.'
    create Canvas application
  • Give the app name and choose a format for how it should look.
    Canvas application format

By doing these steps, we make a tool where we can try out the Dataverse Patch function's abilities.

Establishing Connections and Designing the Interface

To work with Dataverse info, we need to connect. The app's look is made for using Dataverse lists and their parts. 'AAD user' helps make user records and a list is made for them.

Next, a page is made in the app. On this page, we put controls that match the 'Employees' table. We link the table's columns to the right input controls. This makes things easy to use and understand for people.

I have created a screen design something like this,

Design interface

Implementing the Dataverse Patch Function

Our main goal is to use the Dataverse Patch function to handle the data in the 'Employees' table really well. We use the Patch function for this.

Patch(
    Employees,
    Defaults(Employees),
    {
        Name: txtName.Text,
        BirthDate: dpBirthDate.SelectedDate,
        Email: txtEmail.Text,
        Notes: txtNotes.Text,
        Department: ddDepartment.Selected.Value,
        Resume: {
            FileName: First(resume.Attachments).Name,
            Value: First(resume.Attachments).Value
        },
        Skills: multiSelectSkills.SelectedItems,
        Manager: LookUp(
            'AAD Users',
            'Display Name' = ddManager.Selected.'Display Name'
        ),
        Salary: Value(txtSalary.Text),
        ProfileImage: imgProfile.Image
    }
);

This code segment showcases the integration of the Patch function, as it maps input values from controls to their respective columns. The function accommodates various data types, such as text, dates, attachments, lookups, and images.

Output

Canvas Application

Conclusion

This article offers a straightforward, step-by-step guide on saving records in a Dataverse table, even with complex columns.

I hope this helps.

Sharing is caring!


Similar Articles