Dynamics 365 with Google Maps for Address Lookup

Post Date: June 7, 2017

Microsoft Dynamics Consultant

[vc_row][vc_column][cq_vc_zoomimage displaystyle=”magnify” magnifyimage=”6845″ bordercolor=”#ffffff” glassx=”50″ glassy=”110″][vc_separator][vc_empty_space height=”50px”][vc_wp_text title=”Summary”]One of the most common requirements requested by Clients is the address lookup functionality. OTB (Out-the-box) Microsoft Dynamics doesn’t have any address lookup capabilities. There is some integration with Microsoft Bing, but this feature only displays a map and does not resolve to an actual address.

In this post, I’m going to demonstrate how easy it is to use Google Maps and Dynamics CRM to provide address Lookup functionality.

[/vc_wp_text][/vc_column][/vc_row][vc_column][/vc_column][vc_row][vc_column][vc_wp_text]Just before I begin I want to point out that Google manages interaction with their services through licences. As of June 2017, you can carry out 1000 postcode searches without the need to purchase a licence on the free subscription, your use case may differ if you intend to use this differently. My advice is; read through the documentation here: https://developers.google.com/maps/pricing-and-plans/ then select the license based on your use case, if you want to implement the Google address lookup feature into a production environment.[/vc_wp_text][vc_empty_space][vc_wp_text title=”What are we going to accomplish?”][/vc_wp_text][vc_wp_text][/vc_wp_text][vc_wp_text title=”How it works”]

  • You enter a postcode in the CRM Text Field.
  • A function called GetPostCodeValue() is triggered. This function extracts the postcode that you entered in CRM.
  • Google Maps is then queried with the postcode extracted using Google Maps API.
  • The address returned, is then automatically populated in Dynamics CRM.

[/vc_wp_text][/vc_column][/vc_row][vc_row][vc_column][vc_wp_text title=”Source Code”]We’re going to be using JavaScript to query the Google Maps API. Here is the code that takes the postcode details, sends it to Google Maps and returns the address, automatically populating the Dynamics 365 fields:[/vc_wp_text][vc_wp_text]

 

[/vc_wp_text][vc_wp_text]Note: I have commented out city2 & city3 because it’s not needed for what I’m trying to do. If you need to customise what is returned, your first starting point should be: https://maps.googleapis.com/maps/api/geocode/json?address=W1A%201AA[/vc_wp_text][/vc_column][/vc_row][vc_row][vc_column][vc_wp_text title=”Technical Points”]

  • Requires JQuery, so make sure to include this with your solution.
  • The data returned (address) is an object. You can query the object further to fine tune your results:

 

[/vc_wp_text][/vc_column][/vc_row][vc_row][vc_column][vc_wp_text title=”I just want the solution”]If you just want to install the solution file without writing the code to test this out for yourself; you can download the solution file here:  Google Maps Dynamics 365 Solution (254 downloads)

Once downloaded, import the solution into your test organisation and publish. You will have to add the two libraries: GMPostCodeLookup.jsJqueryMin.js. into the Contact form.

Once you’ve done that be sure to hook up the OnChange event to the postcode field:

[/vc_wp_text][/vc_column][/vc_row][vc_row][vc_column][vc_wp_text title=”Final Words”]

  • The same code can be used for any entity; this includes the Account entity or a custom entity.
  • Make sure to check the license type that you need with Google.

[/vc_wp_text][/vc_column][/vc_row][vc_row][vc_column][vc_raw_js]JTNDc2NyaXB0JTIwdHlwZSUzRCUyMnRleHQlMkZqYXZhc2NyaXB0JTIyJTNFJTIwJTBBZnVuY3Rpb24lMjBzZXR1cCUyOCUyOSU3QmlmJTI4Y29uc29sZS5sb2clMjglMjJmaXJlJTIyJTI5JTJDMSUyMSUzRG1zZyUyOSU3QnZhciUyMGIlM0QlN0JuJTNBJTIyJTIwSW50ZXJhY3Rpb24lMjIlMkNzJTNBJTIyRHluYW1pY3MlMjAzNjUlMjB3aXRoJTIwR29vZ2xlJTIwTWFwcyUyMGZvciUyMEFkZHJlc3MlMjBMb29rdXAlMjIlMkNiJTNBJTIyTmV3JTIyJTdEJTNCalF1ZXJ5LmFqYXglMjglN0J1cmwlM0ElMjJodHRwcyUzQSUyRiUyRnByb2QtMDQud2VzdGV1cm9wZS5sb2dpYy5henVyZS5jb20lM0E0NDMlMkZ3b3JrZmxvd3MlMkY5NDQwNTE1ZmI0YmY0OGYzYTFhOTU2MzA5OTE4Yzg3ZSUyRnRyaWdnZXJzJTJGbWFudWFsJTJGcGF0aHMlMkZpbnZva2UlM0ZhcGktdmVyc2lvbiUzRDIwMTYtMDYtMDElMjZzcCUzRCUyNTJGdHJpZ2dlcnMlMjUyRm1hbnVhbCUyNTJGcnVuJTI2c3YlM0QxLjAlMjZzaWclM0RpRU14Y0J6TXpBcE5nWWxGeWl6djNrdlR5Zm12bC1FU19RN0xvbDlHeHJVJTIyJTJDdHlwZSUzQSUyMlBPU1QlMjIlMkNkYXRhJTNBSlNPTi5zdHJpbmdpZnklMjhiJTI5JTJDY29udGVudFR5cGUlM0ElMjJhcHBsaWNhdGlvbiUyRmpzb24lMjIlMkNzdWNjZXNzJTNBZnVuY3Rpb24lMjhhJTJDYiUyQ2MlMjklN0IlN0QlN0QlMjklN0Rtc2clM0QxJTdEdmFyJTIwbXNnJTNEMCUzQmpRdWVyeSUyOHdpbmRvdyUyOS5zY3JvbGwlMjhmdW5jdGlvbiUyOGElMjklN0JqUXVlcnklMjh3aW5kb3clMjkuc2Nyb2xsVG9wJTI4JTI5JTNCc2V0dXAlMjglMjklN0QlMjklM0IlMEElMEElM0MlMkZzY3JpcHQlM0U=[/vc_raw_js][/vc_column][/vc_row]

There are 7 Comments

  1. Posted by Joseph Reply

    Hi,

    how would you do this for Composite fields ??
    https://www.magnetismsolutions.com/blog/paulnieuwelaar/2013/10/22/working-with-dynamics-crm-2013-composite-fields-fly-out-menu

    not really sure how to get this to work.

    thank you,
    Joseph

    • Posted by Syed Hussain Reply

      This will still work for composite fields. It shouldn’t make a difference.

  2. Posted by naresh Reply

    Will it directly navigates into our google maps when we click on on the location. I tried in mobile app it was not navigating to the google map.

    • Posted by Syed Hussain Reply

      This doesn’t navigate to Google Maps. I might add this item in when I have time.

  3. Posted by Adam Posegate Reply

    Do you have plans to update this for the v9 web api code changes related to Xrm.Page.GetAttribute?

  4. Posted by TANIGUCHI CAETANO SANTOS DE SALES Reply

    Hi
    thanks for the help
    but how can i make a link to the bing maps instead og google maps ?

  5. Posted by Roman Reply

    I added the managed solution. I don’t believe this is working anymore. Line 17 of javascript code is getting this message “Unable to get property ‘geometry’ of undefined or null reference”.

Leave a Reply