# Using a Virtual Entity to store historical log (sample)

Hi, my friends,

Today, I will talk about the **Table from external data** *( Virtual Entity).* How to create and configure the virtual table as my sample to store the history of the business process stage.

Firstly, let's quickly discuss [**Virtual Entity**](https://learn.microsoft.com/en-us/power-apps/maker/data-platform/create-virtual-tables-using-connectors?tabs=sql). In short, it can be understood as a 'virtual data table' created within Dataverse with the capability to seamlessly integrate with external data systems. What's even more surprising is that Virtual Entities possess almost all the functionalities of a Standard Entity, except for Rollup, Auditing, and Workflow capabilities.

As of now, Virtual Entity allows us to connect to two main sources: SQL DB and Sharepoint (**Sharepoint list**)**.**

Now, let's proceed with trying to create a Virtual Entity on Dataverse. And I will create the Virtual Entity from an external source - **SharePoint.**

## 1. Create Connection

Firstly, I need to set up a connection to link to an external data source beforehand. I recommend doing this, although, during the Virtual Entity creation process, everyone can add the connection directly.

I will create a new SharePoint connection.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FLmiKzqH0ME7wvJU1k1c0%2Fimage.png?alt=media&#x26;token=6a8ab7b3-9522-4fec-a686-432fe0025d70" alt="" width="351"><figcaption><p>New Connection</p></figcaption></figure>

Next, select the **Source** you want to connect to as SharePoint >> select the option '**Connect directly (cloud-service)**' - I choose this option as my SharePoint Site is created in the Cloud. \
Then click **Create** >> enter the user/pass information to establish the SharePoint Site connection.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F5ovjNDBImuDDAZNZmkTx%2Fimage.png?alt=media&#x26;token=200ea438-af8e-4d5d-982e-e2df7e74a1f9" alt="" width="563"><figcaption><p>Authentication</p></figcaption></figure>

If successfully created, I'll have a connection like the one shown below.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FKV0tdFp1mVw8TamXAn1j%2Fimage.png?alt=media&#x26;token=5a5e3a0a-a74e-4f19-bda0-1476b7b1bee7" alt=""><figcaption><p>Valid Connection</p></figcaption></figure>

## 2. Create Connection Reference

After establishing the connection, the next step is to create a Connection Reference.&#x20;

*Initially, the connection was successfully created, meaning it has stored the authentication details. Creating a Reference Connection for various environments that point to the same connection eliminates the request for additional authentication.*

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FnFO0iE0lwwMksDuQOa8g%2Fimage.png?alt=media&#x26;token=c97d8767-cd7b-46be-be97-5c6de7fe9f3d" alt=""><figcaption><p>Connection and Connection References</p></figcaption></figure>

However, the primary purpose of using Connection Reference instead of direct Connection is to deploy solutions across different environments without encountering authentication errors.&#x20;

*When deploying solutions across different environments, if the solution contains components utilizing connections such as Flows, Canvas Apps, etc., ensuring authentication for the connection is a prerequisite for preventing errors in these components.* \
&#x20;   *If errors occur, the resolution involves entering each environment and re-authenticating each connection. This process is time-consuming and can sometimes be wrong."*

To create a **Reference Connection**, I go back into the Solution:

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F377cDZKM2Imsv9W7Mj11%2Fimage.png?alt=media&#x26;token=dd4cc751-3a34-411d-91b4-3a6269eba3cd" alt="" width="563"><figcaption><p>New Reference Connection</p></figcaption></figure>

Then, fill in the necessary information for the Connection Reference and click **Create**.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F0fmy8sgUMZwkAj4GPSUh%2Fimage.png?alt=media&#x26;token=4ab83c37-ae2f-4bb3-8e12-687049aff0d6" alt="" width="563"><figcaption><p>Configure Reference Connection</p></figcaption></figure>

{% hint style="info" %}
*It's advisable to name the Connection Reference the same on each environment.  Because, when deploying solutions across different environments, the system relies on the 'Name' field of this Connection Reference for mapping purposes.*
{% endhint %}

The Connection Reference had been created:

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FUzq01yXA9HOtWYbD1qkl%2Fimage.png?alt=media&#x26;token=d5e88f9e-08ed-46d8-81ca-1035b5bd4036" alt=""><figcaption><p>Valid Reference Connection</p></figcaption></figure>

## 3. Sample & Create Virtual Entity

First, I prepare a SharePoint List table as shown below:

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FUnCRpAfVcn8kFlgiCf9O%2Fimage.png?alt=media&#x26;token=48f4f82a-f9c1-42a5-9246-d1e83c77b0b6" alt=""><figcaption><p>SharePoint List</p></figcaption></figure>

**The challenge** here is that:\
&#x20;My clients, using D365 CE and the Power Platform, are facing constraints with Dataverse capacity. They wish to track the history of Lead stage transitions without burdening Dataverse's capacity with a vast number of these records. Due to the substantial quantity of Lead records, tracking records become extensive.

As a solution, my team and I proposed using **Virtual Entities** to connect to an Azure SQL DB, storing these tracking records there instead of within Dataverse. This approach effectively reduces the load on capacity. Additionally, leveraging Virtual Entities proves to be swift and convenient, as it's an out-of-the-box solution without requiring excessive coding.

To demonstrate this, I utilized a **SharePoint List (as a substitute for SQL DB)** to create columns for recording Lead stage transition history (as shown in the image above). This SharePoint List is connected to a Virtual Entity in Dataverse, named: "**Lead Tracking table".**

{% hint style="info" %}
To create Lead tracking records, I utilize a **Flow** applied to the **Lead entity's Business Process Flow (BPF)** and **triggered** by the **'Added or Modified'** event, **filtered** by the '**Active Stage'.** However, the **data** will be **generated** on a **SharePoint List.**
{% endhint %}

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FYyncYwPY5DpOfCEtFpmi%2Fimage.png?alt=media&#x26;token=9c95d689-1b28-43b1-84cc-ee19818c9c9d" alt=""><figcaption><p>Flow: Creating Item on SharePoint List - Lead tracking</p></figcaption></figure>

**Let's go back to creating a Virtual Entity.** \
I navigate to **Solution >** The&#x6E;**, click New > Table > Table from external data.**

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FCvQ6zDc2IsiuwY4Dr71a%2Fimage.png?alt=media&#x26;token=8a3497fc-0d5f-4f67-b12e-99dbe2aed58c" alt="" width="563"><figcaption><p>Table form external data</p></figcaption></figure>

Then, select the required integration **Connection**, and I choose SharePoint. Everyone should use **Connection Reference** for this (as image below).

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F3cpSdlBW1OjO3dP8cbT6%2Fimage.png?alt=media&#x26;token=428e0d4c-42d5-4408-a960-91c579375015" alt=""><figcaption><p>Configure Conection &#x26; Reference Connection</p></figcaption></figure>

When choosing the SharePoint connection, the system will prompt me to select the ***SharePoint Site*** or enter the ***URL of the SharePoint Site***.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FqWdtknE1vYOIXHWMAHx1%2Fimage.png?alt=media&#x26;token=f62eb099-5a41-4e86-b79d-1f296a17d08b" alt="" width="375"><figcaption><p>Select SharePoint Site</p></figcaption></figure>

Under the '**Data**' section, I select the ***SharePoint List*** that I want to create as a Virtual Entity on Dataverse

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FTWB42LUcda7w7VrdRybl%2Fimage.png?alt=media&#x26;token=6b9f5768-11e8-42ff-82fd-85e89a25ebb2" alt="" width="375"><figcaption><p>Select Data Soure on SharePoint.</p></figcaption></figure>

Next is the **column mapping for the Virtual Entity**. Initially, the system will automatically map and suggest the Virtual Entity name as well as the column names on Dataverse."

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FGDljhMt4nZiXFM5GM9K2%2Fimage.png?alt=media&#x26;token=9f9b2f1f-abf2-4f01-ba13-13e0bb88a8fe" alt=""><figcaption><p>Mapping column for Virtual Entity</p></figcaption></figure>

*Many might notice more columns than those captured in the SharePoint List I've shown, as these additional fields are OOB (out-of-the-box) and hidden.*

{% hint style="info" %}
It would be great if everyone could name columns on the external source using a **clear convention**. This way, the system will suggest table and column names on Dataverse that are also clear.
{% endhint %}

Finally, click on **Next** > Proceed through the ***Review and Finish*** steps, then click on the **Finish** button to complete the process.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FbmMLQFRteIli4pEJ06A5%2Fimage.png?alt=media&#x26;token=d6842fcd-9eeb-4da6-997a-887938d55429" alt=""><figcaption><p>Configuration finish</p></figcaption></figure>

At this point, we wait for the system to create the Virtual Entity. Once the creation is finished, we'll have a 'beautiful' table like this.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2Fbz4LUPNfIMfGyQmiojXd%2Fimage.png?alt=media&#x26;token=e4345253-64f9-4e8b-b397-545f6a439075" alt=""><figcaption><p>Virtual Table - Lead Tracking</p></figcaption></figure>

## 4. Customize Virtual Entity

Once we have the Virtual Entity, the next step is to drag the fields in Forms, Views, and potentially create new Fields on the Virtual Entity to map with columns from the External Source, in this case, the SharePoint List

{% hint style="info" %}
Here's a tip: to **create columns** on the Virtual Entity, everyone needs to switch to the **Classic interface**. You won't find it on the new UI at make.powerapps.com. :D
{% endhint %}

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FxZMZNTu6bNMObH1X9AND%2Fimage.png?alt=media&#x26;token=bcc696ba-c01a-44c7-9538-acd6d1178b08" alt=""><figcaption><p>Tips: Create new field on Virtual Entity</p></figcaption></figure>

I use this hidden functionality to create the Lookup field in Dataverse. Please try it! :tada:

## 5. Checking

Once the Virtual Entity is created and the Flow trigger on the BPF Lead Process record is set up, now let's try changing the stage and see the results.

**Lead -** I have a Lead record that has gone through 2 stages: Lead > Deal

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FECu7xFUAMUajekSr50Cp%2Fimage.png?alt=media&#x26;token=d4ecc8dd-91c9-42d0-99e9-c594ba8f77f9" alt=""><figcaption><p>Lead record</p></figcaption></figure>

**SharePoint List -** now tracks 2 records when the Lead transitions stages. \
\&#xNAN;*Note:* I adjusted the display of columns on the SharePoint List to make the data presentation more visually appealing, as shown below.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F8BQhO9kxekocpEcmiHxe%2Fimage.png?alt=media&#x26;token=04a2d1a4-d0a7-4dd2-8533-b1cc0e16e873" alt=""><figcaption><p>SharePoint List</p></figcaption></figure>

**Virtual entity** - Lead Tracking

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FvSGb4Z8AQtLnJpzoGL68%2Fimage.png?alt=media&#x26;token=53d503be-6f17-4cbf-8501-7bc84feeb0bb" alt=""><figcaption><p>Virtual entity - Lead Tracking</p></figcaption></figure>

Thank you and hopping help.\
\&#xNAN;**\[NTD]yns.asia**\ <mark style="color:red;">...</mark>[<mark style="color:red;">invite me a cup.</mark>](https://ko-fi.com/ntdyns/?ref=qr\&amp;v=2) :coffee: Thank you. :heart:
