Translate

Sunday, 22 December 2013

Add a button on CRM 2013 form

How to add a button in CRM 2013 form ?

Hello CRM Developers,
          This is my new post to add a new button in CRM 2013.

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 2013 and it will work in CRM 2011(rollup 12) as well as in CRM 2013.

Step 1:- Add a attribute of type single line text on crm 2013 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() {
        var atrname = "YOUR ATTRIBUTE SCHEMA NAME";
        if (document.getElementById(atrname ) != null) {
        var fieldId = "field" + atrname ;
        if (document.getElementById(fieldId ) == null) {
            var elementId = 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%;" >CRM Form Button</button>';
            document.getElementById(atrname).style.width = "0%";
            document.getElementById(fieldId ).onclick = function () { YourOnClickFunction(); };
        }
    }
}

 
Post a Comment