Home > CRM > How to add button to CRM 2011 form?

How to add button to CRM 2011 form?

April 27, 2011

Suppose you want to add a custom button in the CRM Form in 2011 note I am talking about adding button to form not ribbbon, you need to add an attribute in the entity which will then be placed in the Form design and

then the attrbute be converted in a Button at runtime using the javascript below.

The below script can be attached as a web resource file of type Script(JScript).

The Form Onload method can then call the method “create_button_from_textattributeFunction” which will actually create the custom button at runtime.

//CRM 2011 – Custom Button Creator
//Creates a Button from a Text attribute in CRM form.
//For every Button you need, create a Text Attribute and place it on the Form

function create_button_from_textattribute(fieldname, buttontext, buttonwidth,clickevent)
{
functiontocall=clickevent;
crmForm.all[fieldname].DataValue = buttontext;
crmForm.all[fieldname].style.borderRight=”#3366cc 1px solid”;
crmForm.all[fieldname].style.paddingRight=”5px”;
crmForm.all[fieldname].style.borderTop=”#3366cc 1px solid”;
crmForm.all[fieldname].style.paddingLeft=”5px”;
crmForm.all[fieldname].style.fontSize=”11px”;
crmForm.all[fieldname].style.backgroundImage=”url(/_imgs/btn_rest.gif)”;
crmForm.all[fieldname].style.borderLeft=”#3366cc 1px solid”;
crmForm.all[fieldname].style.width=buttonwidth;
crmForm.all[fieldname].style.cursor=”pointer”;
crmForm.all[fieldname].style.lineHeight=”18px”;
crmForm.all[fieldname].style.borderBottom=”#3366cc 1px solid”;
crmForm.all[fieldname].style.backgroundRepeat=”repeat-x”;
crmForm.all[fieldname].style.fontFamily=”Tahoma”;
crmForm.all[fieldname].style.height=”20px”;
crmForm.all[fieldname].style.backgroundColor=”#cee7ff”;
crmForm.all[fieldname].style.textAlign=”center”;
crmForm.all[fieldname].style.overflow=”hidden”;
crmForm.all[fieldname].attachEvent(“onmousedown”,push_button);
crmForm.all[fieldname].attachEvent(“onmouseup”,release_button);
crmForm.all[fieldname].attachEvent(“onclick”,functiontocall);
}

function push_button(){
window.event.srcElement.style.marginLeft=”1px”;
window.event.srcElement.style.marginTop=”1px”;
}

function release_button(){
window.event.srcElement.style.marginLeft=”0px”;
window.event.srcElement.style.marginTop=”0px”;
}

// tell the button what to do when clicked
function functionOnClick()
{
     alert(‘This is a CRM 2011 button click!!!!’);
}

// create the custom CRM button
function create_button_from_textattributeFunction()
{
create_button_from_textattribute(‘name’, ‘CRM 2011 Button’,’184px’, functionOnClick);
}

Advertisements
Categories: CRM
%d bloggers like this: