CRM 2011 How to: set IFrame control content dynamically

February 7, 2011

13 comments

CRM 2011 How to: Set IFrame control content dynamically

CRM 2011 features the Sub Grid  which allows displaying related records grid in the form of the parent entity using only customization tools. For example, displaying all open Opportunities in the form of the parent customer.

This is a great feature which was missing in version 4.0 and required some scripting. Yet, some entities are not supported by this feature. For example, the Audit entity (which is not available in Advanced Find as well. Why???).

To solve this problem, you can use the following function in the parent entity form OnLoad event, while setting the required parameters. Note that you can send the entity from id as an optional parameter in case the Sub Grid is relevant to a specific entity form.

In this example, I used the following parameters to call the function in the Account OnLoad event, assuming the Account form has an Iframe control named IFRAME_audit.

"IFRAME_audit", 1, "areaAudit", "Audit History",""

 

//iframeObjId – iframe control schema name

//objectType  – container entity code

//areaName    – related entity area name

//formId      – entity form id (optional)

function SetIframeContent(iframeObjId, objectType, areaName, iframeTitle, formId)

{   

    //Get iframe control

    var iframeObject = Xrm.Page.getControl(iframeObjId);

    if (iframeObject != null)

    {

        //assemble URL

        var strURL = "areas.aspx?formid=" + formId + "&navItemName=" + iframeTitle + "&oId=" + Xrm.Page.data.entity.getId() + "&oType=" + objectType + "&pagemode=iframe&security=852023&tabSet=" + areaName;

        //Set iframe URL

        iframeObject.setSrc(strURL);

    }

}

By default, when using this solution, the form ribbon lose its context sensitivity. In order to work around this, map the following function to the iframe OnReadyStateComplete event (in the iframe events tab). It’s an ugly solution, but it works:

function RefreshRibbon()
{
    Xrm.Page.ui.navigation.items.get()[0].setFocus();
    Xrm.Page.ui.tabs.get()[0].setFocus();
}

Audit sub grid in Account form

Finally, this function is not documented in the SDK and therefore not supported.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

13 comments

  1. Mike KollingMarch 18, 2011 ב 4:14 PM

    Hi

    I cannot see how this will work with CRM 2011 as the part of the URL you are building up ie the “areas.aspx?formid=” does not exist in the production CRM 2011?

    What version are you running? Is it Beta or RTM?

    Mike

    Reply
  2. Sunil BindraApril 21, 2011 ב 11:05 AM

    Hi
    I have iframe in In Iframe i have a web oage in which i have a grid. In Grid in a column i have a link button in template column. I want to open a window on Link button click i want to open a new window.

    What is etc, eraqs, How i can kame the url exactly so that i can open a new page in new windo.#

    Thanks in Advance

    Reply
  3. ToddMay 2, 2011 ב 8:56 PM

    I used this and it worked great; however, now when the page loads the frame remains activated so the ribbon shows the list tools for that entity and will not change regardless of clicking on any fields or other sub grids. The only way to get it to change is by clicking on one of the associated lists, then clicking back to the main form. Has anyone else experienced this and/or have any resolution for it? I’ve tried using the ribbonrefresh function as well as setting focus to other fields using javascript, but neither of these techniques worked.

    Reply
  4. PatsMay 3, 2011 ב 11:43 PM

    we are facing the same issue as Todd… Did any one had a solution to this. Issue is like, after the form gets load, focus gets onto the Iframe and Ribbon control gets disabled.

    Please help us on this… its really urgent…

    Reply
  5. Yaniv ArditiMay 9, 2011 ב 12:18 PM

    I have updated the post with a workaround for the ribbon problem raised by Pats & Todd.

    Please let me know if that work for you.

    Reply
  6. ToddMay 10, 2011 ב 1:50 AM

    Thanks, Yaniv. That worked. But make sure you check the “Pass Execution context as first parameter” box in the OnReadyStateComplete event. I also found an alternate workaround, using a setTimeout on the main function for just 1 second seemed to do the trick as well. But I think your solution is slightly less ugly than mine, so I went with yours… Thanks again!

    Reply
  7. swapnaliJune 15, 2011 ב 8:12 AM

    hi,
    How to accept different contactnotes in Iframe which locat in account?

    Reply
  8. carmbrusterAugust 30, 2011 ב 4:13 PM

    Hello – The filter option on the grid doesn’t seem to work. Anyone else experience that?

    Reply
  9. shivakumarNovember 15, 2011 ב 12:33 PM

    Hi,
    When i used the the code with little modification i am getting error as “Object Doesn’t Support this Property or method”

    My code is like this
    function test2()
    {
    var iframeObject = Xrm.Page.getControl(IFRAME_Wep_Page);

    if (iframeObject != null)

    {

    //assemble URL

    var strURL = “http://www.google.com”;
    //Set iframe URL

    iframeObject.setSrc(strURL);

    }
    }

    please help me out…

    Reply
  10. James LickDecember 10, 2011 ב 12:14 AM

    I would like to know if “areas.aspx” is an actual aspx page that comes with CRM 2011, or is it something that you added in as a custom page?

    I don’t seem to be able to find “areas.aspx” anywhere in the CRM 2011 website.

    Thanks.

    Reply
  11. ivangDecember 19, 2011 ב 5:12 AM

    Really good solution.
    I just had to use it in a Form with no Navigation Items, where the refreshRibbon function did not work. It took me some debugging to find out that I could achive the same results by using this code:

    loadArea(‘areaProcessSessions’);
    loadArea(‘areaForm’);
    crmForm.GetTab($get(‘tab0’, crmForm), true);

    I hope it helps.

    Thanks,
    Ivan.

    Reply
  12. venkatJuly 4, 2012 ב 12:12 AM

    I am using below function to bind the values dynamically to Iframe, however firsttime it is asking windows credentials to open the CRM page.

    function GetFrameSource(tabSet, StateID) {

    var parentID = StateID;
    var oId = StateID;
    var oType = StateEntity_ObjectType;
    var security = crmFormSubmit.crmFormSubmitSecurity.value;
    crmForm.all.IFRAME_HCR_languages.src = “areas.aspx?oId=” + parentID + “&oType=” + oType + “&security=” + security + “&tabSet=” + tabSet;

    }

    Reply
  13. ArteagaAugust 14, 2012 ב 6:49 AM

    Howdy! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked
    hard on. Any suggestions?

    Reply