Sunday, August 1, 2010

Map or Virtual Earth 6.2 Integrating with Dynamics CRM 4.0

It's very simple to add geo capabilities in Dynamics CRM using Virtual Earth.Use the following steps.

1) Create an ContactLocation.htm file with the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
<title>Select zip/postal code and city</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var map = null;
var location = null;
function GetMap() {
// Open the comments to read values from contact entity page in CRM
var street = "10861 Weyburn Ave";//parent.document.forms[0].all.address1_line1.DataValue;
var state = "California";//parent.document.forms[0].all.address1_stateorprovince.DataValue;
var city = "Los Angeles";//parent.document.forms[0].all.address1_city.DataValue;
var postcode = "90024";//parent.document.forms[0].all.address1_postalcode.DataValue;
var country = "United state";//parent.document.forms[0].all.address1_country.DataValue;

var location = street + ', ' + city + ', ' + state + ', ' + postcode + ', ' + country;
map = new VEMap("contactMap");
map.Find(null, location, VEFindType.Businesses, null, null, null, true, true, true, true, onfound);

//This function used to show the Pin Icon at the searched location
function onfound(layer, resultsArray, places, hasMore, veErrorMessage) {
if (places) {
var shape = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
<body onload="GetMap();">
<form id="form1" runat="server">
<div id="contactMap" style="position:relative; width:600px; height:400px;"></div>

2) Host this file on IIS of the same server of the Dynamics CRM.
3) Open Dynamics CRM and customize the Contact entity’s Main Form:
4) Add a Tab called Map (or whatever you prefer).
5) Add a Section and Iframe called Map in the Location tab.
6) Set the IFrame source as the URL of the hosted html file. Uncheck the Restrict cross-frame scripting option.
7) Save, close and Publish, and is ready.

Now when you view a Contact, go to the Map tab and will be displayed a map as defined address.

No comments: