Create "real" CRM 4.0-Style form-buttons in 5 minutes

by Phil Adams 12. January 2010 16:58

 

Create "real" CRM 4.0-Style form-buttons in 5 minutes

There are several ways to add custom buttons onto a crm form (apart from the boring method of adding buttons via ISV-config 8-):
1. use an iFrame and an external page
Drawback: no offline availability
2.do some DOM-injection and create the buttons at runtime
Drawback: a bit tricky with placement and so on
And then there is:
3. Adis idea to transform a textattribute into a button.
The nice thing is, that you can use the normal formeditor to place it.
So I took the idea further and applied the CRM 4.0 styles to make it look 100% native and more generic to use. (it even reacts to mousedown as expected - hehe ;-)
What to do:

  1. create a textattribute (you can set searchable to "no" so the attribute doesn't show up in advanced search
  2. put it on the form
  3. make it "readonly" (Thanks Marcel!)
  4. copy the sourcecode into the onLoad event.
  5. replace the fieldname "bwt_button1" in the last line with your attributename.
  6. create your functions to tell the button what to do when clicked.
  7. have fun

source:

//////////////////////////////////////////////////////
//////////////////////////////////////////////////////

//CRM 4.0-Style button creator
//Creates a Button from a Textattribute.
//For every Button you need, create a nText Attribute and place it on the Form
//mario raunig, world-direct 04/2008
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
function testfunction()
{
alert('Ta-da!');
}
// create the button
create_button_from_textattribute('bwt_button1', 'What a nice CRM 4.0 Button','184px',testfunction);

//////////////////////////////////////////////////////
//////////////////////////////////////////////////////

Beatnik's Microsoft CRM Blog

Tags:

Comments (1) -

Jim Australia
9/14/2010 2:50:25 AM #

instead of creating an attribute and crowing the entity with useless attributes. why not add an IFRAME and transform the iframe itself. It's just as easy to get a hold of the iframe as it is the field. Something like the following should be suitable;
crmForm.all['IFRAME_myframe'].outerHTML = '<input type="button" value="my button">';

Of course you still need to add all your text. I've used a similar methods to this to embed image tags as well.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Phil

Phil has been working with CRM since the BETA of CRM v1.0 and has seen a lot of the problems arising from installation, maintenance and Development.

Phil specializes in the ISV area of CRM; Creating Add-Ons and Plugins for various clients.

Phil currently works as a Microsoft Dynamics CRM Consultant and Developer for Cambridge Online Systems Ltd In the UK.

Phil also has several Microsoft Certifications in .NET and CRM

Month List

RecentComments

Comment RSS