Pages

Thursday 13 February 2014

Add Button to CRM forms using JScript

Hi Folks,

For this Scenario, I want my custom button below a specific attribute. So i've created a text field and passed that attribute name to my Web Resource. The blow Snippet Code should be added On-Load function of your entity.


------------>
On-Load code
------------->
function addButton(attribute_name) {
    if (document.getElementById(attribute_name) != null) {
        var FieldID = "field" + attribute_name;
        var elementID = document.getElementById(attribute_name + "_d");
        var div = document.createElement("div");
        div.style.width = "20%";
        div.style.textAlign = "right";
        div.style.display = "inline";
        elementID.appendChild(div, elementID);
        div.innerHTML = '<button id="' + FieldID + '" type="button" style="margin-left: 4px; width: 50%; " >Click Me</button>';
        document.getElementById(attribute_name).style.width = "80%";
        document.getElementById(FieldID).onclick = function () {onbuttonclick(); };
    }
}

function onbuttonclick() {
    alert('Button Clicked');
}


While triggering the code we should have to send the schema name of the created textfield, since i want my custom button to be below this text field.

 

the below screen shot shows my custom button on the form



No comments:

Post a Comment