When using Power Automate, there is no default method in the Common Data Service connector to merge accounts, contacts, leads or incidents. As you can see, there is only the ability to create, update or delete records.

That’s a bummer, cause sometimes you want to merge twee records. Luckily it’s possible! You just have to know how.

In the example I’ve got to merge two contacts. I assume you already know how to get the proper contact records, so I won’t go over that.

Since there is no method in the connector, we’ll have to build it ourselves. We’ll use the HTTP method on the HTTP connector.

Start the setup

To setup the HTTP call, let’s start with the basics. Give your action a proper name! Please don’t think lightly about naming actions, since it’s so important to do that right away. It organizes the whole flow so if anyone needs to change it afterwards, they still understand what it’s doing. I named my step ‘Merge Contacts’. Makes sense, right?

The most properties in the HTTP call are easy and fixed. Some of them need some more attention. Let’s first do the easy properties.

  • Method is always POST
  • URI is your CDS / CRM url with the addidion ‘/api/data/v9.1/Merge
  • For the Headers, we need two additional headers
    Accept | application/json
    Content-Type | application/json; charset=utf-8
  • You may leave the Queries empty
  • For the body, please start with this code
{
  "PerformParentingChecks": false,
  "Target": {
    "@@odata.type": "Microsoft.Dynamics.CRM.contact",
    "contactid": "00000000-0000-0000-0000-000000000000"
  },
  "Subordinate": {
    "@@odata.type": "Microsoft.Dynamics.CRM.contact",
    "contactid": "00000000-0000-0000-0000-000000000000"
  },
  "UpdateContent": {
    "@@odata.type": "Microsoft.Dynamics.CRM.contact",
    "contactid": "00000000-0000-0000-0000-000000000000"
  }
}

Now let’s have a look at the body. There are two things you need to change at least. First on line 5, we have the ID of the contact that will be the target. We’ll merge both contacts to this one. Replace the 00000000-0000-0000-0000-000000000000 with the contact id. Look in your previous steps for Contact field with a description containing the Unique Identifier. The double quotes should still be around the Contact field. Second, you need to do the same with with your other Contact, but on line 9.

The only thing that is still to be done is the authentication. Since this is not a predefined connector, you’ll have to deal with the authentication yourself. Authenticating to CDS always works based upon Active Directory oAuth. The tenant is your onmicrosoft.com domein (i.e. consoto.onmicrosoft.com), the Audience your CDS ul and the Credential Type can be set to Secret. The only two things that are left are the Client ID and Secret. You need to setup server-2-server authentication to get these two. If you want to know how? Check my other blog about authenticating with server-2-server authentication.

That’s it! You’re all set and can automate the merge of contact records in CDS.

The post Using Power Automate (Flow) to merge contacts appeared first on Marc Gerner.