Useful CRM Tips

Useful CRM Tips...

Thursday, October 06, 2011

Add a Button Dynamically to Associated Grid


 
     You can achieve the above output, when you do below Customization:

     /* Code To Add a Button to form Associated View Grid */

/* function call on click of the dynamically Created Button */
function AlertMe() {
    alert("Hi...");
}

/* Code Responsible to achieve the above requirement */
var loadArea2 = loadArea;
loadArea = function (area) {
    loadArea2(area);
    if (area == "new_account_new_accountasset") {
        document.getElementById("new_account_new_accountassetFrame").src = document.getElementById("new_account_new_accountassetFrame").src;
        var iframe = document.getElementById("new_account_new_accountassetFrame");
        iframe.onreadystatechange = function () {
            if (iframe.readyState == 'complete') {
                if (iframe.contentWindow.window.document.getElementById('MBcrmGridDisplayInactive') == null) {
                    var li = document.createElement("li");
                    li.id = "_MBcrmGridDisplayInactive";
                    li.className = "ms-crm-Menu";
                    li.title = "Display Inactive";
                    li.tabIndex = -1;
                    li.onclick = function () { AlertMe(); }
                    li.innerHTML = "<SPAN class='ms-crm-Menu-Label'>" +
"<IMG class=ms-crm-Menu-ButtonFirst tabIndex=-1 alt='DisplayInactiveAssets' src='/ITSolutions/_Common/icon.aspx?objectTypeCode=10000&iconType=GridIcon&inProduction=1&cache=1'>" +
"<SPAN id='titlespan' class=ms-crm-MenuItem-TextRTL tabIndex=0>Display Inactive Assets</SPAN>" +
"</A>" +
"</SPAN>";
                    var ele = iframe.contentWindow.window.document.getElementsByTagName("ul");
                    for (i = 0; i < ele.length; i++) {
                        if (ele[i].className == "ms-crm-MenuBar-Left") {
                            ele[i].appendChild(li);
                            break;
                        }
                    }
                }
            }
        }
    }
}

No comments:

Post a Comment