Microsoft Dynamics CRM 2015 Online - Lookup Account Address Via Postal Code Using Bing Maps REST Services

Microsoft Dynamics CRM 2015 Online - Lookup Account Address Via Postal Code Using Bing Maps REST Services

April Blog Series: Spring Cleaning

Insights From: Mark Pitts (Fullscope Senior Developer) 

Some Microsoft Dynamics CRM users may need a way to validate an account's city and state based on the postal code, and the Geocoding Dynamics CRM Data with Bing Maps blog is an excellent resource for this issue. This blog will provide two methods of retrieving the value of the city and state/province, by passing the postal code and the country code to the Bing Maps REST Service. The first method uses a CRM plug-in. The second method uses java-script.

CRM Plug-in:

  • The plug-in will only execute when the account address1_postalcode is modified.
  • If the lookup is successful the fields, address1_city and address1_stateorprovince, are updated.
  • The sample code below relates to a post processing plug-in of the creation of a new account. If immediate results are desired,   register the plug-in to execute synchronously.
  • It is recommended to   create an equivalent plug-in for the 'update' event of the account and implement 'attribute filtering' on address1_postalcode as well as address1_country. This will prevent the plug-in from executing when other parts of the address change.
  • Next, create a Bing map key. This can be done by going to Bing Maps Portal. A Bing Map key is required, even if Dynamics CRM Online is being used.

Microsoft Dynamics CRM Online Java-script:

  • Create a new web resource, account_main_library.js.
  • The script executes only when the account address1_postalcode is modified.
  • If the lookup is successful the fields, address1_city and address1_stateorprovince, are updated.
  • Currently, the script updates the city and state field. However, this java-script can easily be modified to simply validate the city and state, which the user inputs. If the values, returned by the REST call, do not match the user-inputted values, then pass an alert to the user.
  • To avoid the browser limitations of cross-domain scripting, the below code uses jsonp.
  • Add the web resource to the main account form, form properties. Register an event handler on the update of the postal code.
  • Next, create a Bing map key. This can be done by going to Bing Maps Portal. A Bing Map key is required, even if Dynamics CRM Online is being used.​
 
  Explanation of the API:  Find a Location by Address

Definition of the response: Location and Area Types

For more information on how Microsoft Dynamics CRM Online or Microsoft Dynamics AX can help your manufacturing business, contact the experts at Fullscope today.​


CRM, Microsoft Dynamics CRM, CRM Implementation, CRM Technical Tip, Dynamics CRM online