how to create button in crm 4

Odpowiedz how to create button in crm 4

Alle reacties

  • zondag 29 april 2012 17:41
     
     Antwoord

    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.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
    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('Alert'); 
    } 
    // create the button 
    create_button_from_textattribute('bwt_button1', 'What a nice CRM 4.0 Button','184px',testfunction);

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


    • Bewerkt door MubasherSharif zondag 29 april 2012 17:51
    • Als antwoord gemarkeerd door shabnam2012 zondag 29 april 2012 19:08
    •  
  • zondag 29 april 2012 18:47
     
     
    thank you, i try this code.