Microsoft Dynamics CRM IFRAME Magic


Microsoft Dynamics CRM allows you to access external web sites from within forms using IFRAMES (Inline Frames). You can configure the IFRAME to take information from the parent record. A pretty standard use of this is a Web tab on the Account form where the Account’s web site URL is passed to the IFRAME and the web site is available from a Web tab.

larry1

To do this, one sets up a little code for the form On Load event that puts the Accounts web site URL into the IFRAME’s URL. It’s actually pretty simple. Here is the code (assumes you already know how to set up an IFRAME). IFRAME_WebSite is the name of the IFRAME and .src references the URL it uses.

// Load web site URL
{
var AccountURL = crmForm.all.websiteurl.DataValue;
if (AccountURL != null)
{
crmForm.all.IFRAME_WebSite.src = AccountURL;
}
}

Having done this, I thought it would be neat to add a tab to display a map of the Account’s location. I used the same process except I stuffed address fields into the IFRAME URL instead of the web site. The code I used is:

// Load Map URL
{
var AccountStreet = crmForm.all.address1_line1.DataValue;
var AccountCity = crmForm.all.address1_city.DataValue;
var AccountState = crmForm.all.address1_stateorprovince.DataValue;
var AccountZip = crmForm.all.address1_postalcode.DataValue;

var MapURL = "http://maps.msn.com/home.aspx?strt1=" + AccountStreet + "&city1="+ AccountCity+"&stnm1=" + AccountState + "&zipc1=" + AccountZip + "&cnty1=0";

if (MapURL != null)
   {
      crmForm.all.IFRAME_Map.src = MapURL;
   }
}

The code is really pretty simple as you can see. But the results are pretty neat.

larry2

And the Live Search Maps give you different views such as Bird’s Eye which I love:

Larry3

There are lots of things you can do with IFRAMEs. Hopefully this will get your imagination going.

Cheers,

Larry Lentz

Comments (27)

  1. I love this…took me only a few minutes to configure.  Yes, the imagination is running wild.

  2. Joey says:

    I am trying to get that Live Maps with CRM working.

    Can get it to work:

    http://social.microsoft.com/Forums/en-US/crmdeployment/thread/115bbb78-f35c-463d-9a29-2113f02fee85

    Somebody could help me out here?

  3. Jason C says:

    This is a great article, but this concept has already been created many times. It’s available in the CRM As a Rapid Developer Platform book by David Yack and so on. It’s a good article in a public place that will get lots of visibility instead of finding it within a book.

  4. Using IFRAMES you can add lots of neat stuff to your CRM forms. I recently submitted an article to the

  5. Using IFRAMES you can add lots of neat stuff to your CRM forms. I recently submitted an article to the

  6. Matt Holt says:

    Didn’t see a note on this:

    Be sure to uncheck the "Restrict cross-frame scripting" option on the IFrame "General" properties tab…. otherwise you can’t access the fields on the other tabs.

  7. michael says:

    im confused by what to put in the URL line on the form.

    i tried just about everything, even about:blank but it doesnt work.

  8. Sahan says:

    what is the  "&cnty1=0"; for Australia how can i get it

  9. Ken says:

    Neat stuff, but I still have not been able to get a similar clear direction on how to show a contact’s picture in an iframe.

  10. Steve Noe says:

    Good one Larry. Simple & elegant!

  11. ian says:

    Hi All,

    Excellent … excellent article.

    The Country appears to be hard-coded ( i.e. "&cnty1=0" ), what are the mappings for various countries?

    cheers

    ian

  12. Dan Moyers says:

    Great stuff!  We used same technique to pass package tracking information stored in CRM right to UPS’ package tracking site for a client of ours.  Just stuff tracking # from the CRM field into this url –   http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&trackNums=12345&track.x=Track

  13. henrik says:

    I have a hosted https CRM organisation.

    Is it possible to have an iframe showing some http content (not https) even though I have my CRM hosted at a https location?

  14. Chris Espino says:

    Thank you!!!!

    I got it to work with Bing Maps, now I just need to figure out how to remove the "other" elements in the Bing map.

    thanks again!

  15. Keith says:

    Anyone had any issues with this crashing the print preview?   It crashes at the point where you select a printer.  

  16. Michael Ross says:

    I cant get this to load.. to you put the // load map url in the URL line?

    Do you put the rest of the code in on load event??

  17. Larry Lentz says:

    The //load map url (// = comment line) code builds the map url from the Account’s address fields and then it is stuffed into the IFrame url.

  18. Brad says:

    Is there any way to have the country not populate in the URL line?

  19. Voni says:

    Hi,

    Should this work in CRM 3.0?  I am having trouble in 3.0.  No matter what I do, the url I put in the IFrame comes up.

    Any thoughts?

    Thank you!

    Voni

  20. Brent Barnwell says:

    Larry,

    I love this idea and am trying to implement it.  I would like to use both the web page and the maps tab that you referenced.  I got the web page working perfect, but when I go and add the script for the maps portion both the webpage and maps tab display a blank internet explorer window that say, "Try retyping the URL".  When I take the map code back out it works again.  Here’s what my code looks like, (I used google maps):

    {var AccountURL = crmForm.all.websiteurl.DataValue;

    if (AccountURL != null)

    }

    {var address1st = crmForm.all.address1_line1.DataValue;

    var address1st2 = crmForm.all.address1_line2.DataValue;

    var address1city = crmForm.all.address1_city.DataValue;

    var address1state = crmForm.all.address1_stateorprovince.DataValue;

    var address1zip = crmForm.all.address1_postalcode.DataValue;

    var MapURL = "http://maps.google.com/maps?q="+ address1st + ","+ address1st2 + ","+ address1city + "," + address1state + "," + address1zip + ;

    if (MapURL != null)

    }

    {

    crmForm.all.IFRAME_maps.src = MapURL;

    }

    {

    crmForm.all.IFRAME_AccountURL.src = AccountURL;

    }

  21. Oliver Foster says:

    Is there any way to force a link opened within the IFRAME to open in the IFRAME, instead of a new pop-up window?

  22. For those of you, who want the integration with the german bing-map…look here:

    http://blog.protechnology.de/index.php/2010/03/bing-maps-in-dynamics-crm-einbinden/

  23. weijiang says:

    can i get the code how to remove the beside panel ?i just want it show the map only..

  24. Didde says:

    Has anyone moved from bing maps passing customerID and then open CRM Dynamics. So not opening bing maps within a IFrame but opening customerview within CRM from Bing maps

  25. OrdinaryGal says:

    I found error that details below. Please help

    Bing Maps provides US, Europe, the Americas, Africa, Asia, and the World with road, street, and satellite maps. Get driving directions and local traffic conditions, and plan routes to nearby businesses. Use apps to find the lowest gas prices near you, search for nearby parking lots and rates, and calculate taxi fares and taxi routes. Bing Maps uses JavaScript. Either your web browser doesn't support JavaScript or JavaScript is disabled.

  26. Domenic says:

    Does anyone know where we can get the list of country codes?

    So far I've located US = 0; UK=2; Netherlands = 12

    Does anyone know the code for Canada and South Africa?