locked
How to click on a Ribbon button with Javascript RRS feed

  • Question

  • Hi Experts ,

    i want to know how to click on a ribbon button in Javascript.  For instance based on the value of a speci field  i want to programmatically click on a specific ribbon button. How can i achieve this?

    Thanks


    If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

    Tuesday, April 24, 2012 8:46 AM

Answers

  • If you just want to trigger the click of the ribbon buttons, you can trigger with the following code.

    window.top.document.getElementById("new_test|NoRelationship|Form|Mscrm.Form.new_test.Assign-Large").click();

    The ID of the ribbon buttons are in the following format.

    <entityname>|NoRelationship|Form|<buttonid>-<buttontemplate>

    e.g.
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Save-LargeMedium
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Collaborate-LargeMedium
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Workflow-Large
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.ExportData-LargeMedium

    You can check the button IDs in the HTML tags using IE developer tool.

    window.top.document.childNodes[1].innerHTML



    Tuesday, April 24, 2012 10:12 AM

All replies

  • You can check the Actions called by the buttons with Visual Ribbon Editor and you can call those functions in your code.

    Re-use of JavaScript functions defined within ribbon commands is unsupported extension though.

    e.g.

    Mscrm.RibbonActions.addActivityOnForm("4202");
    
    assignObject("10000");


    Tuesday, April 24, 2012 9:36 AM
  • Hi Linn thanks for the Post,

    my main goal is to click those button via javascript, it can be interesting to know which actions or functions those buttons calls, but now can i call those function on my on javascript library? how can reference the MS Library in my form in other to call those actions?


    If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

    Tuesday, April 24, 2012 9:43 AM
  • You don't need to reference the Ribbon JS Library.

    Since the ribbon has already loaded the necessary JavaScript on the document, you just use those commands in your JavaScript and it'll perform as you click the buttons.

    e.g.

    Mscrm.RibbonActions.addActivityOnForm("4202");

    Once again, Re-use of JavaScript functions defined within ribbon commands is unsupported extension and the solution may not work properly if the structure of the ribbon commands are changed in new releases.

    Tuesday, April 24, 2012 9:52 AM
  • If you just want to trigger the click of the ribbon buttons, you can trigger with the following code.

    window.top.document.getElementById("new_test|NoRelationship|Form|Mscrm.Form.new_test.Assign-Large").click();

    The ID of the ribbon buttons are in the following format.

    <entityname>|NoRelationship|Form|<buttonid>-<buttontemplate>

    e.g.
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Save-LargeMedium
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Collaborate-LargeMedium
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.Workflow-Large
    new_test|NoRelationship|Form|Mscrm.Form.new_test.MainTab.ExportData-LargeMedium

    You can check the button IDs in the HTML tags using IE developer tool.

    window.top.document.childNodes[1].innerHTML



    Tuesday, April 24, 2012 10:12 AM