2 min read

Another View of CRM Data

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