[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.
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:
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.
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.