Virtual table walkthrough using the OData v4 Data Provider

Imagine that you want to access, create, update, and delete some personal information about a contact from an external data source within your model-driven app. In this simple walkthrough, you will model a virtual table named Person with columns mapped to the external schema to these operations at runtime from an OData web service.

Data source details

Because the data source used for this walkthrough has an OData v4 web service, we can use the OData v4 Data Provider included with your environment.

Web service url: https://contosowebservice.azurewebsites.net/odata/

Important

  • The web service url used for this walkthrough isn't a functioning web service.
  • You can't use the OData v4 Data Provider to connect to another environment.

For this walkthrough, a single virtual table that contains the following columns is needed.

External column name External data type Virtual table data type Purpose
Id Edm.Guid Primary key Primary key for the table
FirstName Edm.String Single line of text First name of the person
LastName Edm.String Single line of text Last name of the person
Age Edm.Int32 Whole number Age of the person
LastModifiedOn Edm.DateTimeOffset Data and time Last modified data and time of the person record

The OData metadata of the external data source person table:

Odata external data source XML part 2.

Create the data source

Create the data source for the OData v4 data provider that uses the OASIS Open Data Protocol (OData) sample web service.

  1. Go to Settings > Administration > Virtual Entity Data Sources.

  2. Select NEW, select OData v4 Data Provider, and then select OK.

  3. Enter or select the following information.

    Field Value
    Name Person Sample OData Data Source
    URL https://contosowebservice.azurewebsites.net/odata
    Timeout 30
    Return Inline Count Client-side Paging
    Return Inline Count True

Leave the other columns as-is, and select SAVE & CLOSE.

Tip

When using your own web service, verify that the URL is valid by pasting it in to your web browser. If you want to understand the columns and data types respective to the table you are interested in, you can append /$metadata to the end of your URL to see the definition of tables in you web service.

Open solution explorer

Part of the name of any custom table you create is the customization prefix. This is set based on the solution publisher for the solution you’re working in. Make sure that you are working in an unmanaged solution where the customization prefix is the one you want for this table. More information: Change the solution publisher prefix

Open an unmanaged solution

  1. From Power Apps select Solutions from the left navigation pane, and then on the toolbar, select Switch to classic. If the item isn’t in the side panel pane, select …More and then select the item you want.

  2. In the All Solutions list open the unmanaged solution you want.

Create the virtual table

  1. In the left navigation pane of solution explorer, select Entities, and then select New from the main pane.

  2. On the Entity: New form, select the Virtual table option, and then enter the following information:

    Field Value
    Data Source Person Sample OData Data Source
    Display Name Person
    Plural Name Persons
    Name new_person
    External Name People
    External Collection Name People
    Notes (includes attachments) selected
    Activities selected

    Note

    The OData resource path semantics uses EntitySet to identify the resource. In the sample OData web service, the EntitySet is defined as People. This value is used as the External Name for the virtual table Person.

  3. Next to Areas that display this entity, select Sales, and then select Save (but don’t close the table form). Person table definition.

Create the columns for the virtual table

On the left navigation pane of the Entity: Person page, select Fields. As part of this walkthrough, you will edit two existing columns and add three more columns that are available in the external data source.

Important

External names are case sensitive. Refer to your web service metadata to make sure you use the correct name. A Nullable value of false indicates that the attribute is required. Notice that primary key columns are always system required.

  1. Open the new_personid column, and change the following property with the value indicated here:

    External Name: Id

    Create id column.

  2. Select Save and Close.

  3. Open the new_name column, and change the following properties to have the values indicated here:

    • Display Name: Last Name
    • External Name: LastName

    Create last name column.

  4. Select Save and Close.

  5. Select New, and on the Field: New for Person page enter the following information:

    Field Value
    Display Name First Name
    Name new_firstname
    External Name FirstName
    Field Requirement Business Required
    Data Type Single Line of Text

    Create age column for person.

  6. Select Save and Close.

  7. Select New, and on the Field: New for Person page enter the following information:

    Field Value
    Display Name Age
    Name new_age
    External Name Age
    Field Requirement Business Required
    Data Type Whole Number

    Create age column.

  8. Select Save and Close.

  9. Select New, and on the Field: New of Person page enter the following information:

    Field Value
    Display Name Last Modified On
    Name new_lastmodifiedon
    External Name LastModifiedOn
    Field Requirement Business Required
    Data Type Date and Time

    Create last modified on column.

Add the columns to the main form

  1. On the Person table window, select Forms.

  2. Open the main form, drag and drop the First Name, Age, and Last Modified On columns from the right pane onto the form in the General section.

    First name, age, and last modified on columns added to main form.

  3. On the Person table window, select Save and Close.

Configure the default view

  1. On the left pane of the solution explorer, under the Person entity, select Views.
  2. Open the All People view.
  3. In the Common Tasks pane, select Add Columns. Add columns for view.
  4. Select the First Name, Age, and Last Modified On columns, and then select OK.
  5. On the View: All People window, arrange the column order by selecting the move left and move right arrows, and then select Save and Close.
  6. On the Solution Explorer window, select Publish All Customizations.
  7. After all customizations are published, close the Solution Explorer window.

Use the virtual table in a model-driven app

Create a model-driven app and add the Person table to the site map. Then, select the Person main form and the Person Advance Find view. Publish the app. More information: Build your first model-driven app from scratch

Then, app users can perform read, create, update, and delete operations using the virtual table just like any other table in Microsoft Dataverse.

Create, view, and delete records using the virtual table

  1. Run the model-driven app. Select New, complete the required columns, and then save the record.
  2. Select New again to create another record and save it.
  3. You should now have two records similar to the following in the All Persons view. View All Persons.
  4. To delete a record, select a person record and then select Delete. Confirm to delete the record on the confirmation page.

See also

OData v4 Data Provider configuration, requirements, and best practices
Create and edit virtual tables that contain data from an external data source