Category: Power Automate

Using Power Automate (Flow) to merge contacts

Using Power Automate (Flow) to merge contacts

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.

Using Dynamics 365 CRM lookups and alternate keys in Microsoft Flow

Using Dynamics 365 CRM lookups and alternate keys in Microsoft Flow

I’ve written a blog a while ago on using alternate keys with the Dynamics 365 / CRM WebApi. You can read the blog here. The post guides you in creating an alternate key and identifies some usage scenario’s.

Lately I’ve been working on an integration between Eventbrite and Dynamics 365 / CRM with Microsoft Flow. Currently I’m going back and forth between enthusiasm and disappointment. Sometimes it does more than you would expect and sometimes you’re missing the details you are looking for.

Lookup

Most often you would want to set a lookup value in a record you are creating and updating. With flow this might be a bit hard as looping is cumbersome, or even impossible, to implement (e.g. nested loops are not supported).

The first thing you could do it set hard coded values. E.g. when creating a product in CRM it’s sometimes feasible to hard code the unit of measure. Simply pasting in the Guids works fine in such case:

Alternate key

Other time you want want to set a lookup to a record you are also integrating. E.g. with Evenbrite you have the ‘entity’ Events that I integrate with a custom entity Events. Event tickets I’m integrating with a custom entity Event tickets. On that event ticket entity I need to set the lookup to the related event. One option would be query for the event in CRM using Flow and setting the value.

However, to simplify things, I’ve created an alternate key on the Event entity in CRM, using the EventId from Eventbrite. Now setting the lookup is fairly easy, and we don’t have to query CRM to fetch the record. This sample works perfectly:

Conclusion

For now, Microsoft Flow seems to be a perfect tool to do lightweight integration scenario’s. Using alternate keys might really help in making your life a little easier in extending the options you have with Microsoft Flow.