Dataverse Auditing Part 2 – Retrieve Old Value for Dataverse Record Using HTTP With Azure AD

Extending our exploration of auditing within Dataverse, we’ll employ the ‘HTTP With Azure AD’ action in Power Automate to retrieve the previous value of a modified record.

Before proceeding with this tutorial, it’s essential to have auditing enabled in your environment. If you’re not sure how to do this, please consult the first episode in this series for step-by-step guidance.

Business Value

“Garbage In, Garbage Out.” You’ve probably heard the importance of data integrity. Ensuring data consistency and quality is pivotal because it lays the foundation for reliable analytics and decision-making. Audit trails serve a dual purpose: they not only make users responsible for their actions within the system but also offer invaluable data points for analysts to identify trends, facilitating smarter business decisions.

Framework

Solution

In this tutorial, our focus will primarily be within the context of a solution. A solution serves as a container where we organize and house the components related to the digital transformation we are undertaking. While we won’t delve into an exhaustive explanation, it’s important to understand that solutions provide a structured framework for managing and deploying our project’s components.

Datasource

With auditing activated in our setup, go ahead and pick a table to experiment on. For this demonstration, I’ve selected the “Accounts” table from Dataverse’s Common Data Model.

Retrieve Environment URL

To access the Environment URL required for our flow, navigate to the ‘Power Platform Admin Center.’ This URL is crucial for configuring the flow within its respective environment.

Upon reaching the Admin center, follow these steps:

  1. Navigate to the left-hand side navigation menu.
  2. Select “environments.”
  3. Choose the specific environment you are currently working in.

This will allow you to access the environment URL needed later on.

Copy the environment URL and paste it for use later on.

Environment Variable

In our workflow, especially for the ‘HTTP with Azure AD’ action, we will create an environment variable. This variable will store the URL specific to our environment, which we will subsequently incorporate into the request URL for this action.

By leveraging environment variables, you’re not just streamlining your current workflow; you’re future-proofing your solution. When the time comes to move your solution to a new environment, you can easily update these variables to align with the context of the new environment. This ensures that your solution maintains its agility and effectiveness, regardless of where it’s deployed.

In your solution, follow these steps to create a new environment variable:

  1. Select “+New.”
  2. Click on “More.”
  3. Choose “Environment Variable.”

This will initiate the process of creating a new environment variable within your solution.

For the form, please complete it as follows (note that there is some flexibility with the Display Name and Description):

  1. Copy and paste the previously retrieved environment URL into the “Default Value” field.
  2. Save the changes.

This step ensures that the environment URL is properly integrated into the flow, facilitating the seamless configuration of your flow.

Connection Reference

Before we proceed to configure our flow, there’s one more crucial task to enhance its robustness. We need to create a connection reference for the ‘HTTP with Azure AD’ action. This connection reference serves a similar purpose to the environment variable by enabling the flow to seamlessly transition to a new environment while establishing a connection to the resources within that environment. This step ensures the continuity and adaptability of our flow across different environments.

Inside our solution, follow these steps to create a connection reference:

  1. Select “+New.”
  2. Click on “More.”
  3. Choose “Connection Reference” to open the connection reference form.

This form will allow us to establish a connection reference for our flow, enhancing its flexibility and portability across different environments within the solution.

In the connection reference form, follow these steps:

  1. Name the connection reference.
  2. Optionally, add a description.
  3. From the connector dropdown, select ‘HTTP with Azure AD.’
  4. In the connection selector, click “+ New connection” to create a new ‘HTTP with Azure AD’ connection. This action will open a new tab where you can set up the connection details for ‘HTTP with Azure AD.’

In the new tab for connection details, follow these steps to create our connection:

  1. Select ‘Connect directly (cloud-services).’
  2. Enter the environment URL that we retrieved from the admin center earlier into the “Base Resource URL” field.
  3. Enter the environment URL in Azure AD Resource URI (Application ID URI) field.
  4. Select Create to create connection.
Creating connection

5. Next, you will be prompted to select an account to establish the connection with. Once you’ve chosen the account, the connection will be created, solidifying the link between your flow and the ‘HTTP with Azure AD’ action.

Return to the tab with the connection reference form and follow these steps:

  1. Select the refresh button to ensure your newly created connection is visible.
  2. Choose your newly created connection from the list.
  3. Finally, select “Create” to create the connection reference.

This step will integrate the connection reference into your solution.

Flow

Time to build a flow!

Within your solution, proceed as follows:

  1. Select “New.”
  2. Choose “Automation.”
  3. Select “Cloud Flow.”
  4. Opt for “Automated” to set up your flow.
  5. You will be directed to a screen where you can name your flow and select its trigger.

For the purposes of this demo, you’ve named your flow ‘Account Updates’ and selected the Dataverse trigger, specifically, ‘When a row is added, modified, or deleted.’ Now, proceed by selecting “Create” to start configuring your flow.

In the trigger configuration, set the following parameters:

  1. For “Change type,” select “Modified.”
  2. For “Table name,” choose “Accounts” or the table of your choice.
  3. Set the “Scope” to “Organization.”

These parameters will define the trigger conditions for your flow, ensuring it activates when a row is modified in the specified table.

Let’s add a new step to your flow. Follow these steps:

  1. Search for “HTTP with Azure AD.”
  2. Select “Invoke an HTTP request.”

To ensure that your connection reference is properly selected, follow these steps:

  1. Click on the three dots in the top right corner of the “Invoke an HTTP request” action.
  2. Confirm that your connection reference is correctly chosen. This step is essential for maintaining the flow’s integrity if you decide to migrate the solution to a different environment.

To configure the “Invoke an HTTP request” action, follow these steps:

  1. For the HTTP method, select “GET.”
  2. In the URL field of your request, use the following template:
{Environment Variable URL}/api/data/v9.2/RetrieveRecordChangeHistory(Target=@target,PagingInfo=@paginginfo)?@target={'@odata.id':'[table plural name](GUID of the updated record from our trigger)'}&@paginginfo={"PageNumber": 1,"Count": 1,"ReturnTotalRecordCount": true}

Replace the placeholders with the appropriate values:

  • {Environment Variable URL} should be replaced with the actual environment variable you created.
  • [table plural name] should be replaced with the name of the table (in plural form).
  • (GUID of the updated record from our trigger) should be replaced with the GUID of the updated record obtained from your trigger.

This configuration sets up the HTTP request to retrieve the record change history based on the trigger’s parameters.

Make sure to validate and adjust the URL according to your specific environment and requirements.

For the action headers, follow these steps:

  1. Switch to text mode by selecting the ‘T’ icon.
  2. Copy and paste the following headers configuration:
{
  "Accept": "application/json",
  "OData-MaxVersion": "4.0",
  "OData-Version": "4.0",
  "If-None-Match": "null",
  "Prefer": "odata.include-annotations=\"*\""
}

To simplify, follow these steps:

  1. Add a “Compose” action to your flow.
  2. In the “Compose” action, select the output from the “Invoke an HTTP Request” action as its input.

This way, you’re capturing the output from the HTTP request for further use in your flow.

Save your flow.

To test your flow, follow these steps:

  1. In Dataverse, open the table you are working on.
  2. Edit the value of a field on an existing record within that table.

This action will trigger your flow, allowing you to verify that it responds correctly to the changes made in Dataverse.

Old Value
New Value
Changes reflected in flow

Leave a Reply

Discover more from Duke DeVan

Subscribe now to keep reading and get access to the full archive.

Continue reading