Thursday, 12 July 2012

Insert Custom button on CRM Form using javascript in CRM 2011

In this article , I am going to explain how to insert button using javascript on CRM Form along with attribute like below image




Call this function on Form onload event and pass attribute name as parameter


function addButton(attributename) {
    if (document.getElementById(attributename) != null) {
        var sFieldID = "field" + attributename;
        var elementID = document.getElementById(attributename + "_d");
        var div = document.createElement("div");
        div.style.width = "19%";
        div.style.textAlign = "right";
        div.style.display = "inline";
        elementID.appendChild(div, elementID);
        div.innerHTML = '<button id="' + sFieldID + '"  type="button" style="margin-left: 4px; width: 100%;" ><img src="/_imgs/ico_16_4210.gif" border="0" alt="Dial this number"/></button>';
        document.getElementById(attributename).style.width = "80%";
        document.getElementById(sFieldID).onclick = function () {onbuttonclick(); };
    }
}

function onbuttonclick() {
    alert('Hi');
}

3 comments:

  1. great stuff...

    Reply Delete
  2. You should put a disclaimer...This is unsupported customization and should be avoided unless and until absolutely required. As a general rule anywhere getElementById is used we should be avoiding that.

    Reply Delete
  3. OK Abhishek , Thanks for your advice :)

    Reply Delete

Note: only a member of this blog may post a comment.