Welcome to MSDN Blogs Sign in | Join | Help

Catherine Eibner

Dynamics, SQL, .Net & getting them all to play nicely together!
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! :)

Posted: Tuesday, December 02, 2008 3:32 PM by ceibner

Comments

Rocco Cutri said:

Nice blog Catherine :)

I thought I would send you a link to some work we have done with one of our clients Diabetes Australia using SQL integrated with Microsoft Virtual Earth.

http://www.ndss.com.au/Australian-Diabetes-Map/Map/

I'm sure you would find it really cool !

We launched it in Federal Parliament and it has been live for 2 months now.

# December 10, 2008 2:50 AM

Mattpan said:

Thanks for the help on this. It seem when in run the html file nothing happens just a blank screen. Any help would be appreicated.

# December 15, 2008 2:45 PM

Jeremy Sand said:

I am not able to get this to work.  I have follow your directions to a "T" and the IFrame remains blank.

Any Ideas?  Do I need to modify any portion of your code?

# December 15, 2008 10:22 PM

jgould763 said:

I'm having the same trouble as Mattpan.  Just a blank IFrame.

# December 15, 2008 10:54 PM

ceibner said:

Ok 2 questions for those having issues with this:

1. Can you load the HTML file directly if you add arbitrary values for the variables such as:

         var name= 'Test';

         var street1 = '1 Epping Rd';              

         var state = 'NSW';

         var city = 'Sydney';

         var postcode = '2031';

         var country = 'Australia';  

2. If you are running this on a VPC - does it have internet access and can you access the http://dev.virtualearth.net site?

# December 16, 2008 12:02 AM

Sailaja said:

Whan I try to open this Java Scriptsource file

http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2">http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2

I am getting the following eror:

The XML page cannot be displayed

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx...

var L_invalidinvoketarget_text="Invalid invoke target specified.",L_invaliddirections_text="Invalid argument passed; both st...

It didn't worked for me both MSCRM 3.0 andf MSCRM4.0

# December 19, 2008 6:51 AM

ceibner said:

Hi Sailaja,

I am not sure why you are trying to access the ashx source file directly? You should be creating a HTML file that links to it as per the code sample in the <html></html> tags in the post above.

If you want to test that you can get the Virtual Earth Map istelf to load - try the following very simple HTML code. Create a new HTML page & paste the below into it:

<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()

     {        

       map = new VEMap('myMap');

map.LoadMap();

     }  

 </script>

 <body onload="GetMap();">

      <div id='myMap' style="position:relative; width:600px;

height:400px;"></div>

 </body>

</html>

This code just loads an instance of Virtual Earth within a HTML page. Save the HTML page, and then open it in a browser to test to see that this page works & can load the default Virtual Earth viewer.

# December 20, 2008 9:37 PM

Sailaja said:

Hi Ceibner,

Thanks a lot for the reply.I am getting another error when I placed the code into CRM server by following your article. But when I open the Account form, it is showing nothing on the screen, and in the corner of the page showing Error as follows:

Line :19

Char:10

Error:'VEMAP' is Undefined

Code:0

URL: http://localhost:5555/AddIns/VirtualMap.htm

Thanks for your help in advance.

# December 22, 2008 2:59 AM

ceibner said:

Hi Sailaja,

Check that you have external internet access from the Server itself - especially if it is a VPC. Can you open the sample page I included in my reply above on your CRM server directly & get it to load?

Thanks,

Catherine

# December 22, 2008 6:24 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker