Posts Tagged ‘Attach Event to CRM’


This is an example on how to create a button on the form, using java script. First of all we need to create a nvarchar attribute and put it on the form where we want our button.
In this example my attribute’s schema name is new_test.

Here is the code

/*———————————-*/

someFunction = function()

{

alert(“button clicked!”);

}

// This is how we call the button, what we see

crmForm.all.new_test.DataValue = “Button”;

// We could align it a bit

crmForm.all.new_test.style.textAlign = “center”;

crmForm.all.new_test.vAlign = “middle”;

//we make the mouse look as a hand when we’re moving over

crmForm.all.new_test.style.cursor = “hand”;

crmForm.all.new_test.style.backgroundColor = “#CADFFC”;

crmForm.all.new_test.style.color = “#FF0000”;

crmForm.all.new_test.style.borderColor = “#330066”;

crmForm.all.new_test.style.fontWeight = “bold”;

crmForm.all.new_test.contentEditable = false;

//we attach some events in order to make it look nice 🙂

crmForm.all.new_test.attachEvent(“onmousedown”,color1);

crmForm.all.new_test.attachEvent(“onmouseup”,color2);

crmForm.all.new_test.attachEvent(“onmouseover”,color3);

crmForm.all.new_test.attachEvent(“onmouseleave”,color4);

function color3() {

crmForm.all.new_test.style.backgroundColor = “#6699FF”;

}

function color4() {

crmForm.all.new_test.style.backgroundColor = “CADFFC”;

}

function color1() {

crmForm.all.new_test.style.color = “000099”;

}

function color2() {

crmForm.all.new_test.style.color = “FF0000”;

}

//here we attach what we want our button do

crmForm.all.new_test.attachEvent(“onclick”,someFunction);
Replace a field to a label (use replaceNode())
/* replace new_field_d to a label */
if (crmForm.all.new_field != null)
{
var html = document.createElement( “”);
html.innerText = “this is a lable”;
crmForm.all.new_field_d.replaceNode(buttonText);
}

Append text under a field (you don’t need to create an attribute for that)
/* append text under new_field */
if(crmForm.all.new_field != null)
{
var html= document.createElement( “”);
html.innerText = “this is a text field”;
crmForm.all.new_field.parentNode.appendChild(html);
}

Advertisements