← Back to Blog

Using Azure Logic Apps to Integrate Dynamics CRM 365

Use Azure Logic apps to integrate your line of business applications to Dynamics CRM 365

I wanted to test how logic apps would work for integrating our line of business task management system to our Dynamics CRM Online tenant.  I won’t cover the setup that got me here in hopes this will have interest for both technical and non-technical audiences.  The point here was to see how quickly I could implement a one-way integration from our custom app to CRM.

Pictured below is the Azure logic app with everything collapsed to a summary level.  The overview that I will cover in more detail below is that I define my integration frequency and get data from my source system in the first step, and in the next group of steps, check each record to see if it exists in CRM, and conditionally depending on if it exists already then update the CRM record or if not create the record.

Designer View Summary

All of these connectors are built into Azure for CRM online but I was curious if I could do this my way which I knew from experience would make this integration really easy.  Specifically, I wanted to be able to use the GUID from my custom system as CRM’s ID when I create the record.  The reason I wanted to do that was so that I could use the “CRM Online – Get record” rather than the retrieve multiple and if the Get Record failed then I knew it didn’t exist in CRM and I could go ahead with the create. The idea is pictured below.

Designer View Details

The problem doing it this way, I knew, was that the Azure Logic app was going to be using the equivalent of a Retrieve and if I run a Retrieve using a GUID that doesn’t exist then I will actually get an error returned instead of null…so I needed to find a way to handle the control flow of the logic app; luckily there is a code view…I needed it for multiple modifications that aren’t yet supported in the designer view.

To make sure my condition shown above would be executed even after the “Find CRM Task by ID” step failed (which it would do anytime the source task didn’t exist in CRM yet), I needed to modify the “runAfter” statement shown below so that it included both Failed and Succeeded.

Code View Flow Control

The other change I needed to make in the code view was to map my custom app’s task id to CRM’s activityid.  The Task entity’s ActivityId is not shown as available for mapping in the designer but I knew that CRM’s web-services would allow me to specify the id on create…so doing this works just fine.

Code View Field Mapping

Here is the partially expanded view of the Update and Create conditional actions.

Design View Condition Details

Now that I have it all setup, I can run the job manually or wait for the schedule to hit and confirm everything is in CRM as expected.

It's worth noting too that editing in the code view will sometimes prevent you from being able to use the designer view without losing the changes you made in code view...so keep a backup of the code view.