The Microsoft Dynamics CRM Blog
News and views from the Microsoft Dynamics CRM Team

Another View of CRM Data

Another View of CRM Data

  • Comments 3

[Code examples are on the CRM Sandbox in the downloads section.]

MS Dynamics CRM shipped with grid view and form view for displaying data such as account or contact information. However, that does not mean it is the only way to present CRM data. This article will show a way to represent CRM accounts on a map.

account map.PNG
Populating account's coordinate.

Before we can show the account on the map, we first need to populate account's location into CRM. Most account/contact already contains shipping or billing address. However, they are not in the format that is easy to map or locate. Out of the box, account already contains 'latitude' and 'longitude' attributes that we can use but they are not automatically populated by CRM.

So we need to convert the human readable street address into latitude and longitude coordinate. This process is called geocoding. For existing CRM deployment where accounts and contacts are created without latitude and longitude, we need to mass-populate them using web service information in the CRM SDK. The are several providers that offer geocoding service such as:

In this example, we use the MapPoint web service. It is free of charge but you need to register for developer account before you can use it. There are some restrictions on developer account so double check before using it on commercial system. For new account that will be created after this initial mass-populating, we could incrementally populate latitude/longitude for them using JavaScript on form's OnSave event or using server side callout.

Sometimes, it might be easier to geocode each account's address on the fly and plot them on the map every time. However, doing so would cause serious performance and unnecessary load time. Moreover, after getting location data into CRM, we can do something interesting such as optimizing delivery/service truck route based on sales order's account/contact address.

Displaying Account on the Map

In this sample, we will just show each account on map using Virtual Earth map control (http://dev.live.com/virtualearth/sdk). It is quite easy to use after we get account’s latitude and longitude. Another interesting part is how do we query actual accounts from saved query. The steps are like this:

- Retrieve the actual fetch XML on savedquery entity.
- Convert that fetch XML into QueryExpression object using FetchXmlToQueryExpressionRequest.
- Use the QueryExpression to retrieve list of accounts.

For better performance, we can also cache the QueryExpression so we don't have to look it up every time and save 2 web service calls but we are not doing it for simplicity. JavaScript then use XmlHttpRequest to send request XML to our QueryService and gets back XML. I manually created request XML and parsed response XML. However, you can use ASP.Net AJAX to create JavaScript proxy and save some more time.

Showing account in map view is just one of another way to use CRM data. We hope to publish some more examples in the near future. But for now, we trust this example will provide some interesting concepts and ideas to consider for your implementation of CRM.

Cheers,
Ake

  • Very cool Ake. One of the issues that I found when building a similar solution for geo based scheduling was that the default long and lat input masks on the CRM Account object aren't in the format that mapping applications accept.

    Out of the box, MS CRM has the latitude and longitude fields set to accept values from 0 to 1 billion with a decimal precision of two. In order to match the formating accepted by mapping services the longitude should be changed to accept values from +180 to -180 with five decimal places of precision. The latitidues need to be modified to accept +90 to -90 with five decimals of precision.

    Barry

  • This would be great if we could gain access to UK postal data =(

  • I did something like this with Googlemap and included some integration with postcode anywhere for UK geocoding. see http://www.crmrocks.net/ and the post called Microsoft CRM Googlemap Mashup

Page 1 of 1 (3 items)
Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post