Get Geo Co-ordinates from Address values in Common Data Service Records

This is a reference post for another blog post I am working on. I figured it would be a good as standalone post as well.

Power Automate has opened up a whole new world of connectors and APIs that would traditionally have been reserved for professional developers. A great use case for Power Automate calling an external API (application programming interface) is to get the geo coordinates (latitude and longitude) based on physical address data.

Anyone using Dynamics 365/Dynamics CRM will know that the Account and Contact entities in the Common Data Model already have fields for latitude and longitude, as well as address fields for street, city, state/province, postal code and country.

Over the years there have been plug-ins and workflow extensions developed to retrieve the latitude and longitude values from existing APIs (such as Bing or Google).

It is now 2020, Power Automate to the rescue! Below are the steps to quickly create a flow to get the latitude and longitude co-ordinates based off an address in the Account record.

Bing Maps API

Before I can create a flow, I will need to setup a Bing Maps developer account.

Navigate to the Bing Maps Portal. Click on the Sign In button to create a new developer account.

Bing Maps Developer

Either choose your default windows login or choose a different account.

Sign In with an account

Enter in your details and agree with the Terms and Conditions

Details

We will need an API key for our flows and other projects. Click on My account and choose My Keys.

Generate Keys

Provide and application name (it can be anything) and for now choose the key type as Basic and the Application type as Dev/test.

Create key

A new key will be generated. Copy this value as we will need it to create our flow.

Create Power Automate flow to get Latitude and Longitude

For my example I am using the original Common Data Service connector so I can use the “When a record is selected” trigger to manually run the flow against Account records in my model-driven Power App (or Dynamics 365). However, you could utilize just about any trigger (e.g. scheduled or when a new Account record is created or when the address changes)

Create a new flow

I choose the Default environment and selected the Accounts entity.

Trigger when an Account is selected

For the next step I choose the Bing Maps connector and then the Get location by address (preview) action.

Get location by address action

The following prompts are when you will need to enter in a connection name (can be anything) and the API key you created earlier. Note that if you plan on running this flow a lot you will need to acquire a proper subscription for the Bings maps service.

Enter in API key

If the key is valid, the next step you will need to specify the address fields and use the Dynamic content to feed to the Bing Maps API.

Add Account address fields to Bing Maps Action

The next step we will want to update the Account record latitude and longitude fields based on the address. Choose the Common Data Service (current environment) connector and the Update a record action.

Update a record

We will want to update the Account record that triggered the flow.

Update triggering Account record.

NOTE: If you are planning on triggering this flow from an update of the Account record, make sure that you add trigger filters so that the flow will not run in an endless loop! This will consume all your Bing API calls as well as your flow allocations!

Open up advanced settings and from the dynamic content update the latitude and longitude fields on the Account record.

Updating Account record

Testing the Flow

From a model-driven app (which could be Dynamics 365) select one or many of the Account records and from the main menu, choose Flow and then select the flow we created.

Run the Get Coordinates flow

After the flow runs (it may take a few moments) you should see that the latitude and longitude field values have been updated.

Summary

This is a pretty simple flow and a great example of how Power Automate can be used to read data from a web based API and update data in the Common Data Service. Having the latitude and longitude on the Account records is useful for Dynamics 365 Field Service scenarios and for displaying maps on Power Apps portals.

Cover Photo by Jamie Street on Unsplash

Nick Doelman is a Microsoft Business Applications MVP, and a Microsoft Certified Trainer. Nick is also an instructor on https://365.Training delivering a variety of Power Platform classes. Follow Nick on twitter @readyxrm

2 thoughts on “Get Geo Co-ordinates from Address values in Common Data Service Records

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s