Translate

Sunday 18 September 2016

Add a button on CRM 2016 form.

How to add a button in CRM 2015/2016 form ?

Hello CRM Developers,
          This is my new post to add a new button in CRM 2015/2016.

I can understand the CRM developers requirements, because after release of CRM roll up 12 and CRM 2013, we can access CRM on cross browsers also. when we did customization with java script functionality, It may vary browser to browser, so there may be need of yours to add a custom button in CRM 2013. So here is the simple java script code for CRM 2015/2016 and it will work in CRM 2011(rollup 12) as well as in CRM 2015/2016.

Step 1:- Add a attribute of type single line text on crm 2016 form. Or you may use existing one.

Step 2:- Add the fallowing code to your crm java script web resource. And call this function on page load.
     
function createButton(atrname) {
       
        if ( window.parent.document.getElementById(atrname ) != null) {
        var fieldId = "field" + atrname ;
        if ( window.parent.document.getElementById(fieldId ) == null) {
            var elementId = window.parent.document.getElementById(atrname + "_d");
            var div = document.createElement("div");
            div.style.width = "100px";
            div.style.textAlign = "right";
            div.style.display = "inline";


            childDiv = elementId.getElementsByTagName('div')[0]
            childDiv.style.display = "none";

            elementId .appendChild(div, elementId );
            div.innerHTML = '<button id="' + fieldId + '"  type="button" style="margin-left: 3px; width: 100%;" >Click Me !!</button>';
            window.parent.document.getElementById(atrname).style.width = "0%";
            window.parent.document.getElementById(fieldId ).onclick = function () { YourOnClickFunction(); };
        }
    }
}