Integrating Dynamics CRM 4.0 with Virtual Earth

I wrote a post a while ago about integrating CRM 3.0 with Virtual Earth. I had on my To Do list since CRM 4.0 was released to re-write this post to work with the newer version of CRM. Since then Virtual Earth ahs also had new versions released so this post really needed an overhaul.

Today I got asked to do just that and so as I now had the excuse to do it, here is the new blog post to accompany it! :-)

The integration points into CRM 4.0 haven’t changed a great deal, but the Virtual Earth Version 6.2 has got a few changes and so the script file is a little different. I have included below the steps for integrating the two:

 

Virtual Earth Script

1. Create a HTM file that includes the following code. In this example I called the file MappingLink.htm:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
  <script>

      var map = null;
      function GetMap()
      {        
          var name= parent.document.forms[0].all.name.DataValue;
          var street1 = parent.document.forms[0].all.address1_line1.DataValue;             
          var state = parent.document.forms[0].all.address1_stateorprovince.DataValue;
          var city = parent.document.forms[0].all.address1_city.DataValue;
          var postcode = parent.document.forms[0].all.address1_postalcode.DataValue;
          var country = parent.document.forms[0].all.address1_country.DataValue;  

         map = new VEMap('myMap');
         map.LoadMap();
         if(city!='') map.Find(name, street1+', '+city+', '+state+', '+postcode+', '+country, VEFindType.Businesses, null, 0, 1, true, true, true, true, onfound);
         else map.FindLocation('Sydney, Australia');
      }  

        function onfound(layer, resultsArray, places, hasMore, veErrorMessage)
        {
         if (places) {
        var name= parent.document.forms[0].all.name.DataValue;
        var shape = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
                shape.SetTitle(name);
                map.AddShape(shape);
            }
        }     
  </script>

  <body onload="GetMap();">
       <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
  </body>

</html>

 

2. Create a folder in your CRMWeb Directory on the CRM Server and save the above file in it. For this Example I added a folder Called AddIns

CRM Customisations

3. Customise the account form by going into the Settings –> Customization –> Customize Entities -> Account –> Forms & Views –> Form

4. Add new Tab, in my example I call it VE Map.

5. Add a new Section, giving it a Section Name such as Map & optionally selecting whether you would like the Section name to appear on the form

6. Add an IFrame to the section created above & point the URL field to the file you created in Steps 1 & 2 above. For my example this is: /AddIns/MappingLink.htm. Ensure that you untick the “Restrict Cross Frame scripting” check box – otherwise your JavaScript will not be able to access the Account form fields it needs to determine the address to look up. I also changed the Formatting tab to select the “Automatically expand to use available space” option.

image

7. Publish your changes to the Account Entity.

Now when you browse to your CRM Account, click the new Tab VE Map & it loads the Virtual Earth Map, Maps to the address on the Client account, and adds a push pin with the Name of the company displayed when you hover the mouse over the Pushpin.

image

You can now play around with the freely available Virtual Earth features as well – such as the below screenshot which displays the results with the Birdseye View:

image

This is a really quick & simple example of the potential of integrating these two technologies. I would love to see what people are doing with these two, especially some examples for things like Directions, traffic, heat maps, suggested service call optimisation, and so many more locationally aware concepts! :)