Labels

Tuesday, June 2, 2015

Audit History Details in Iframe

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

function SetIframeContent()
{
    var iframeObjId = "IFRAME_audit"; //Iframe Schema Name
    var objectType = 1;//Account
    var areaName = "areaAudit";
    var iframeTitle = "Audit History";
    var formId = Xrm.Page.data.entity.getId();
    formId = formId.replace('{', '').replace('}', '');
    //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).

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