1. 程式人生 > 實用技巧 >Virtual Table on Power Apps with OData

Virtual Table on Power Apps with OData

Virtual table walkthrough using the OData v4 Data Provider

Effective November 2020:

  • Common Data Service has been renamed to Microsoft Dataverse.Learn more
  • Some terminology in Microsoft Dataverse has been updated. For example,entityis nowtableandfieldis nowcolumn.Learn more

This article will be updated soon to reflect the latest terminology.

Imagine that you want to access ticket information from an external data source within your model-driven app. In this simple walkthrough, you'll model a virtual table with columns mapped to the external schema that retrieves ticket data 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.

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

External column nameExternal data typeVirtual table data typePurpose
TicketID Edm.Guid Primary key Primary key for the table
Title Edm.String Single Line of Text Title of the ticket
Severity Edm.Int32 Whole Number Number value of 0-4 indicating the severity of the ticket

The OData metadata of the external data source Ticket table:

XML
<tableType Name="Ticket">
  <Key>
    <PropertyRef Name="TicketID" />
  </Key>
  <Property Name="TicketID" Nullable="false" Type="Edm.Guid" />
  <Property Name="Title" Type="Edm.String" />
  <Property Name="Severity" Nullable="false" Type="Edm.Int32" />
</tableType>

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 toSettings>Administration>Virtual table Data Sources.

  2. SelectNEW, selectOData v4 Data Provider, and then selectOK.

  3. Enter or select the following information.

    FieldValue
    Name Contoso Sample Data Source
    URL https://contosowebservice.azurewebsites.net/odata
    Timeout 30
    Return Inline Count True

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

Tip

When using your own web service, verify that the URL is valid by pasting it in to your web browser.

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. If you care about the customization prefix, 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

  1. From the Power Apps portal selectSolutions, and then on the toolbar, selectSwitch to classic.

  2. In theAll Solutionslist select the unmanaged solution you want.

Create the virtual table

  1. In the left navigation pane of solution explorer, selectTables, and then selectNewfrom the main pane.

  2. On thetable: Newform, select theVirtual tableoption, and then enter the following information:

    FieldValue
    Data Source Contoso Sample Data Source
    Display Name Ticket
    Plural Name Tickets
    Name new_ticket
    External Name Ticket
    External Collection Name Tickets
    Notes (includes attachments) selected
    Activities selected
  3. Next toAreas that display this table, selectService, and then selectSave(but don’t close the table form).

Create the columns for the virtual table

On the left navigation pane of thetable: Ticketpage, selectColumns. As part of this walkthrough you will edit two existing columns and add a third column.

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 thenew_ticketidcolumn, and change the following attribute with the value indicated here:External Name: TicketID

  2. SelectSave and Close.

  3. Open thenew_namecolumn, and change the following attributes to have the values indicated here:

    • Display Name: Title
    • External Name: Title
  4. SelectSave and Close.

  5. SelectNew, and on theField: New for Ticketpage enter the following information:

    FieldValue
    Display Name Severity
    Name new_severity
    External Name Severity
    Field Requirement Business Required
    Data Type Whole Number
    Minimum Value 0
    Maximum Value 4

  1. SelectSave and Close.

Add the columns to the Main form

  1. On the Ticket table window, selectForms.
  2. Open the main form, drag and drop theSeveritycolumn from the right pane onto the form in theGeneralsection under theTitlecolumn.
  3. On the Ticket table window selectSave and Close.

Configure the default view

  1. On the left pane of the solution explorer, under theTicket table, selectViews.
  2. Open theAll Ticketsview.
  3. In theCommon Taskspane selectAdd Columns.
  4. SelectSeverity, and then selectOK.
  5. On theView: All Ticketswindow selectSave and Close.
  6. On the Solution Explorer window selectPublish All Customizations.
  7. After all customizations are published, close the Solution Explorer window.

View the virtual table in action with Dynamics 365

  1. Go toService>Extensions>Tickets.

    TheAll Ticketsview displays. Notice that you may need to refresh your browser to view the table from theServicearea.

  2. Open aTicketrow to view the form that includes theTitleandSeveritycolumns for the given row.