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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Select zip/postal code and city</title>
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></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.LoadMap();
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);
shape.SetTitle(location);
map.AddShape(shape);
}
}
</script>
</head>
<body onload="GetMap();">
<form id="form1" runat="server">
<div>
<div id="contactMap" style="position:relative; width:600px; height:400px;"></div>
</div>
</form>
</body>
</html>

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:

Loading...