Make Your Common Data Service Transactions Atomic Using ChangeSets in Power Automate Flows

Leave a comment

A new feature in the Common Data Service (Current Environment) connector for Power Automate Flows is the ability to use transactions when performing some platform operations. In this post, we will look at how to use these changeset transactions, which is useful if you need to ensure your create/update/deletes are atomic, meaning if one transaction fails, they all fail, and if one succeeds, they all succeed. This is also useful as you transition your Workflows in Dynamics 365 Power Apps to Microsoft Power Automate Flows. Note these features are available under the Common Data Service (Current Environment) connector, which is different from the Common Data Service Connector.

To use the Common Data Service (Current Environment) connector, go to https://flow.microsoft.com and create a new Solution:

Give the solution a name and click Create:

Note if you don’t do this, you will only see the standard Common Data Service connector, not the Common Data Service (Current Environment) connector.

Now, go into the solution and select New->Flow:

This opens a new blank Flow. Let’s create a simple Flow that, when an Account is created in Dynamics 365, we will create a new Contact, add that contact to the account that was created, and update the annual revenue of the account created. We see the new flow created:

Now, search for Common Data Service, and you will see 2 options appearing. Zoom over to find the Current Environment connector:

You will now see Triggers and Actions. Let’s first set up our trigger. Select When a record is created, updated or deleted:

On selecting it, we see we need to choose our Trigger condition, Entity Name and Scope:

For trigger condition, we will select Create:

And then Accounts. For Scope, choose from Business Unit, Organization, Parent: Child Business Unit and User. We will choose Organization:

Next, add a new step and choose the same Common Data Service (Current Environment) connector:

Choose Executes a Changeset Request:

You should now see below, where we can Add an Action. Let’s add a couple of actions to demonstrate a simple example:

Clicking Add an Action gives us 3 options for our changeset request – Create a New Record, Delete a Record and Update a Record:

Let’s create a contact called Bob Smith and set the Account to the one just created:

Create a new action to update the Account created:

We will update the Account that was created and set the Annual Revenue to 1000000:

The flow should look like below:

Create a new Account and Save it, then refresh until the changes appear. We see the contact has been created and assigned, and the annual revenue is set:

Now let’s update the flow so one of the steps in the transaction will fail, and as a result, the whole transaction will fail. We will change the account we update from the one that was created to a non-existant account:

Save the Flow.

Now, create a new Account:

In the flow, we see the whole changeset fails as it cannot find the account to update, which means the contact is not created either:

I’m sure you will find some interesting use cases for these in your specific business requirements, feel free to share in the comments below.

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *