Dynamic Ribbon Button Drop-Down Menu

Respuesta propuesta Dynamic Ribbon Button Drop-Down Menu

  • Monday, May 14, 2012 3:24 PM
     
      Has Code

    Hello All!

    First off, let me state that I’m very new to Dynamics so please forgive me for any ignorance. J
    Here is my dilemma. I’m trying to create a ribbon button which can dynamically generate the elements of a drop-down menu. I’ve found an article which goes over the process of generating the elements of such a menu on the fly, but it is mostly just a proof of concept.

    For instance, the javascript function that the article uses to populate the menu is not very useful, seeing as a static list could achieve the same effect. Here is the example population function.

    function DynamicMenu(CommandProperties) {
        ///<summary>Dynamically generate menu items based on context</summary>
        /// <param name="CommandProperties">
        ///    Command properties crm parameter sent from the ribbon.  object used to inject the Menu XML
        /// </param>
        var menuXml = '<Menu Id="Sample.DynamicMenu">' +
                        '<MenuSection Id="Sample.Dynamic.MenuSection" Sequence="10">' +
                            '<Controls Id="Sample.Dynamic.Controls">' +
                                '<Button Id="Sample.account.form.Controls.Button.FirstButton"' +
                                        ' Command="Sample.SearchCommand"' +
                                        ' LabelText="First Button"' +
                                        ' ToolTipTitle="First Button"' +
                                        ' ToolTipDescription="The first button"' +
                                        ' TemplateAlias="isv"' +
                                        ' Sequence="20" />' +                                  
                            '</Controls>' +
                        '</MenuSection>' +
                    '</Menu>';
        CommandProperties.PopulationXML = menuXml;
    }

    However, I would like to use this same concept to populate a list based off of data that has been stored in dynamics. For example, in our current configuration we have an entity called “Teams”. Currently, these teams can have tasks assigned to them through a dialog in a different entity ("Cases") which queries for teams that are assignable then populates a list with the results. What I would like to do is skip the dialog entirely and populate a ribbon button’s drop-down menu with assignable teams that have been found through a query.

    I feel that the limiting factor in this issue is JavaScript and the information that it is given access to. Ideally I would like to do a query from a custom populate script which performs the query and builds the menu, but I’m not sure that that is possible. I was looking into the following function, but I’m unsure as to what information you can actually glean from it.

    Thank you, any comments or suggestions will be appreciated!

All Replies

  • Tuesday, May 15, 2012 11:10 PM
     
     Proposed Answer

    Hi Kirk,

    You could do a query against the CRM OData WebService to get a list of teams that are assignable. From there, you could do a loop through each record and create the Dynamic Ribbon menu using your javascript function above.

    http://crmscape.blogspot.com.au/2011/03/crm-2011-odata-json-and-crm-forms.html

    Alternatively, you could create a lookup field for the Team and have a custom Filtered Lookup View created to only display teams that are assignable.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits


  • Thursday, May 17, 2012 12:09 PM
     
     

    Dimaz,

    Thank you very much for the reply. Those look like some excellent solutions, I'll have to keep them in mind for the future. I actually ended up creating an aspx page that performs the query which is accessed by a ajax request upon the execution of the populate command. That way the generation of the flyout's xml is all done server side, all javascript has to do is receive the response. :) 

    Thanks again for the help.