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="">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src=""></script>

      var map = null;
      function GetMap()
          var name= parent.document.forms[0];
          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');
         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];
        var shape = new VEShape(VEShapeType.Pushpin, places[0].LatLong);

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



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.


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.


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:


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! 🙂

Comments (18)
  1. Rocco Cutri says:

    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.

    I’m sure you would find it really cool !

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

  2. Mattpan says:

    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.

  3. Jeremy Sand says:

    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?

  4. jgould763 says:

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

  5. ceibner says:

    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 site?

  6. Sailaja says:

    Whan I try to open this Java Scriptsource file″>

    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 ‘

    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

  7. ceibner says:

    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=""&gt;



     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

     <script type="text/javascript"



         var map = null;

         function GetMap()


           map = new VEMap(‘myMap’);




     <body onload="GetMap();">

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




    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.

  8. Sailaja says:

    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


    Error:’VEMAP’ is Undefined


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

    Thanks for your help in advance.

  9. ceibner says:

    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?



  10. Ricardo Nunes says:

    Hi do you know how to integrate virtual earth with microsoft dynamics nav 5.0? Best regards

  11. Loli says:

    Hello Catherine,

    First : THANKS !!!!!!!!! that’s wonderful.

    I integrate this and it works perfectly …. one exeception : I still have this following error :


    The closest match for ‘9 rue marcelin Berthelot, Issy les Moulineaux, null, 92130, France’ is ‘92130 (postcode), France’. If the closest match is incorrect, enter the complete address including country name and commas, and try again."

    It seems it doesn’t treat the "street adress". Do you have an idea about what is wrong ?

    Thanks a lot


  12. ceibner says:

    Hi Loli,

    Thanks for your comment. I have a question for you – does the address entered like that actually work to locate the correct place if you go to the map page in the SDK here:

  13. Loli says:

    Thanks for your reply,

    Yes I tested it as a basic user in the VE application. It works very well.

    What is surprising, is the calling address "’9 rue marcelin Berthelot, Issy les Moulineaux, null, 92130, France’ ":

    adresse 1 = 9 rue marcelin Berthelot

    city = issy les moulineaux

    postalcode = 92130

    country = france

    but what is "null" between city and postal code ?

    Thanks a lot for your help,


  14. Dustin says:


    Thanks for posting this, it is great!  Unfortunately, I need a little help please.  It’s my fault, I’m sure.

    I’m puzzled, the path you cite “/AddIns/MappingLink.htm” is not my path for the CRMWeb folder.  Mine is C:Program FilesDynamics CRMCRMWeb.  I’m running SBS 2003 if it matters.  I’m confused by the slashes I would expect the backslash, not the forward slash you use.

    So, I tried putting the folder on the root of C: on the SBS server, I then get a java error about the “var name= parent.document.forms[0];” being null or not an object or something like that.  Sorry, I’m not in front of it right now.

    I then coped the htm file and added dummy data to it and executed it on the server and it worked.  I’m thinking it’s a sharing issue.  I’ve tried various edits to the ACL, but I’m not strong on that.

    Could you please give me a dummies version of the path (UNC?) and any ACL/sharing modifications needed to get the CRM web client to be able to access the file?  My thought is the CRM web client can’t get to the htm file.

    Thank you so much!!!

  15. Dustin says:

    Disregard my 1st post.  I am trying to get this to work on the lead entity.  I did it on the Account and it works fine.

    I’m sure I need to make a seperate htm file for the lead entity, but I’m not sure what to chnage for it to work.  Please help.


  16. Dustin says:

    I fixed it!!

    I only changed line 11


    var name= parent.document.forms[0];


    var name= parent.document.forms[0].all.companyname.DataValue;

    All the other atributes between the two forms are the same, only account uses "name" and lead uses "companyname"

    There are other instances of the "name" lable, but that does not seem to be an issue.  So, I’m not going to monkey with it!

    Thank you so much for posting this, I really needed the mapping solution.  It is puzzling why this is not included out of the box.  ACT! has MapQuest built into it’s products.  None the less, I have it now!  Thanks!

  17. freeal says:

    Is it possible to add company address, phone or something else to push pin?

    Have you made maps with route? I have try to find solution for that.

  18. Hi, this is a great post, thanks for sharing.

    I have also posted a very similar post about CRM and Virtual Earth that may help the ones that need another view for this solution.…/default.aspx

    Hope it helps.


    Alejandro Cesetti

    Microsoft Dynamics CRM Consultant

    System Engineer

Comments are closed.

Skip to main content