Dynamics 365 v9 Virtual Entity using OOB OData v4 Provider - PART 2

In my previous blog Dynamics 365 v9 Virtual Entity using OOB OData v4 Provider - PART 1, we created a Web API using OData v4 format.

In this blog post, we are going to create the virtual entity in Dynamics 365.

Login to Dynamics 365 with system admin role. Go to Settings -> Administration -> Virtual Entity Data Sources. Click + NEW button to create a new data source.


As shown above, there are a few things you need to know.

  • URL: the URL to the Web API we deployed in previous post.
  • Pagination Mode: I always select Client-side Paging. The difference between Client-side Paging is described below.
  • Return Inline Count: I always set it to True. The client-side paging won't work if you don't set this to True.
With Client-side Paging, the OBB OData v4 Data Provider uses $Skip and $Top parameters in the URL to get the correct records in each of the pages.

For example: /Jobs?$top=25&$select=JobName,ScheduledStart,CustomerId,JobId&$count=true


However, if you set the Return Inline Count to False. Then the request Url will be: /Jobs?$top=25&$select=JobName,ScheduledStart,CustomerId,JobId

The $count parameter will be missing in the Url. And Dynamics 365 will only display 25 records (assuming user's personal preference is 25 in Dynamics 365) if there are more than 25 records. Users can only see the first page of the records and they won't be able to click the next button to see the rest of the records.

That is why I always set Return Inline Count to True and just let Dynamics 365 handle the paging.

The first page Url will be:
/Jobs?$top=25&$select=JobName,ScheduledStart,CustomerId,JobId&$count=true

Second page Url will be:
/Jobs?$skip=25&$top=25&$select=JobName,ScheduledStart,CustomerId,JobId&$count=true

With Server-side paging, the page size is defined in the external web service, the Web API in this case. The Get method in the Web API will be different from what's shown in blog post PART 1. For more details on server-side paging, please refer to this link: https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options#server-paging

At the time of writing this blog post, it doesn't seem like the OOB OData v4 Data Provider respects the Server-side paging option. It means that even I set the Pagination Mode to Server-side Paging, Dynamics 365 still uses $skip and $top parameters to get values.

Now, after saving the new Data Source record, go to solutions. Either use the default solution or create a new unmanaged solution.

Before you start configuring the new virtual entity, just open the metadata of the Web API, like the one below.



 In the unmanaged solution, create a new custom entity like below.


Once you save the change, a new virtual entity called Job is created. And by default, Dynamics 365 creates the JobId and Name field for you. Next step is to update the JobId and Name field with correct External Name.

Job Id field:

<Property Name="JobId" Type="Edm.Guid" Nullable="false"/>



Name field:

<Property Name="JobName" Type="Edm.String"/>



Then, we are going to add two new fields, Customer and Scheduled Start.

Customer field:

<Property Name="CustomerId" Type="Edm.Guid"/>



Scheduled Start field:

<Property Name="ScheduledStart" Type="Edm.DateTimeOffset" Nullable="false"/>



Now, go to the main form and add the fields to the main form. You can also add the fields to the Card and the Quick View Form too. Then go to the views, add the fields to all the available views.

After all the above, navigate to the Jobs entity from Sales area, you will see the home grid like below.


In the next post, we will try using Advanced Find, viewing jobs from the customer record, and set up a dynamics marketing list for account.

Dynamics 365 v9 Virtual Entity using OOB OData v4 Provider - PART 3

Comments

Popular posts from this blog

Dynamics 365 sub-grid add new and add existing

Dynamics 365 Web API get entity using alternate key value that has apostrophe/single quote in it

TLS 1.2 and PowerShell