locked
how to add javascript code to an existing menu item in crm 4.0 menu item toolbar. RRS feed

  • Question

  • Hi All,

    I've a custom entity which is 1:N relation with opportuinity entity. so the link to custom entity is appearing in each opportunity. when I go to the entity, I've two menu items 'New.. ' and 'Add existing..' on the menu tool bar. I want to execute a javascript functionality for those menu items. How can I do this. I really appreciate your help on this.

    Tuesday, November 16, 2010 7:15 AM

Answers

All replies

  • Hi Bittu,

    You can use DOM (Document Object Model) to get menu items in JScript and then adding onclick event on that menu items.

    To learn DOM basics (if you already don't have equipped with) you may refer to this short tutorial document I have written for the purpose. Link: Document Object Model

    If you want you may review the sample code for using DOM in MS CRM here . Although it is not specific to your stated task but can give a good understanding.

    To ascertain elements to get from MS CRM pages, you may download and use IE8 Toolbar.

    Regards,

     


    Paradise lies at the feet of thy mother. - Prophet Mohammed (PBUH)
    Tuesday, November 16, 2010 7:26 AM
  • Check this link to attach the various element in CRM

    http://www.henrycordes.nl/post/2008/04/CRM-attach-event-to-onclick-of-tab.aspx

    The link contains example for tab in your case it should be Menu button.


    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Mark as answer if a post has answered the question
    Tuesday, November 16, 2010 8:02 AM
  • Hi Amol,

    I'm trying to find the Id of the left navigation menu item in the opportunity form. But none of left navigation items are retrieved when I try to find the items using Javascript. However I used IE developer tool and able to find the id. when i try to find the control using id in javascirpt. it says object not found message. can you help me out here....

    below is the sample code I'm using:


    var lis = document.getElementsByTagName('LI'); //all the menu options
    var i = 0;

    while (i < lis.length)
    {
    alert(lis[i].getAttribute('id'));
     
     var as = lis[i].getElementsByTagName('a'); //all the anchor items inside the menu items
     var j=0;
     while(j<as.length)
     {
     alert(as.getAttribute('title'));
     j++;
     }
        i = i + 1;
    }

    Wednesday, November 17, 2010 12:17 PM
  • Hello all,

     

    Kindly help me out here. I really need a solution now.....

    Friday, November 19, 2010 5:08 AM
  • Hello all,

    I have some R&D and now I'm able to do what I require. Here is the solution.

    Goto inetpub folder in the server. under this folder navigate to sfa/opps/edit.aspx.

    open this page and you can find the 'onload' script. There you can search for the 'Li' elements and crawl within them to get your required option.

    ex:

    var mylist = document.getElementsByTagName('Li');

    var i = 0;

    while(i<mylist.length)

    {

    if (mylist[i].getAttribute('title') == 'title of the element you want to disable')

                    mylist[i].style.display = 'none';

    i=i+1;

    }

     

    What I would like to know is 'Is it a supported customization'. I dont think this survives during upgrade to next version. share your thoughts friends.

     

    Friday, November 19, 2010 12:39 PM
  • This is unsupported
    Mahain : My Dynamics CRM Blog
    • Proposed as answer by Future MVP Friday, November 19, 2010 2:56 PM
    Friday, November 19, 2010 2:05 PM
    Moderator
  • Hi Mahender,

    Yes, you are correct... I've shifted the code to form OnLoad event of the form.

    Monday, November 22, 2010 9:16 AM