web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Fly out button populatequerycommand

(0) ShareShare
ReportReport
Posted on by 25

Hi there, 

I am working on a flyout (in the ribbon) that should load dynamically the menu items (buttons). I have a PopulateQueryCommnand coupled to the query from the flyout button. When I hardcode the menu items and don't call a webapi function for example .RetrieveMultiple the flyout is correctly populated. Then when an async call is executed and I try to populate it in the promise .then function with the same hardcoded values the flyout keeps showing loading. 

When I do an async await pattern the same result. Reading all the community posts and on other sites there is stated that it isn't possible to populate with an async web api call. How can the flyout be populated with a normal retrievemultiple query async (sync isn't supported anymore). Or is it really that a xmlhttprequest with a sync call must be executed to let this work correctly. Or should it be loaded for example in the onload that the data is loaded and in the populatequery function validate if the data is available?

Thanks in advanced for your help. 

Regards, 

Stefan 

I have the same question (0)
  • Suggested answer
    Nya Profile Picture
    29,060 on at

    Hi Stefan,

    Please refer to the following article, which may help you:

    Daynight: MS Dynamics CRM 2011 - Ribbon Drop Down Menu (makdns.blogspot.com)

     

    Any other details are also appreciated; e.g. illustrative image of the specific effect you want to achieve.

  • Stefan Verheggen Profile Picture
    25 on at

    Hi Nya, the post send is different. Maybe the only way to get it working. What happens in the post is that the user right/role is retrieved outside the Report Menu function. What I like to do is retrieve data in the function async this doesn't work. It doesn't work in an async/await pattern and also not when using the promise then() structure.

    The code is:

    var command = "rav.quote.ChangeCurrency.Command";

           var entityName = "quote";

           var page = "Form"

           if (Xrm.Internal.isUci()) {

               command = entityName + "|NoRelationship|" + page + "|" + command

           }

           var formContext = primarycontrol;

           var ole = formContext.getAttribute("rav_oleid").getValue()[0].id;

           var transactioncurrency = formContext.getAttribute("transactioncurrencyid").getValue()[0].id;

           this.commandProperties = commandProperties;

           var querystring = "?$select=currencyname, transactioncurrencyid&$filter=rav_rav_ole_transactioncurrency/any(o:o/rav_oleid eq " + ole + ") and (transactioncurrencyid ne " + transactioncurrency + ")";

           var currencies = [];

           var menuXml = "";

           // has to be executed sync otherwise the items aren't populated. refreshRibbon etc. doesn't work.

           //var promise = this.ExecuteHttpRequestSync("GET", "transactioncurrencies", querystring);

           //promise.then(

           //    function (response) {

           //        if (response && response.value) {

           //            for (var i = 0; i < response.value.length; i++) {

           //                currencies.push(response.value[i]);

           //            }

           //        }

           //        if (currencies.length > 0) {

           //            formContext.ui.clearFormNotification("change_currency_on_quote_notification_id");

           //            menuXml += "<Menu Id='rav.quote.ChangeCurrency.Menu'>";

           //            menuXml += "<MenuSection Id='rav.quote.ChangeCurrency.MenuSection' Sequence='10'>";

           //            menuXml += "<Controls Id='rav.quote.ChangeCurrency.Control'>";

           //            for (var i = 0; i < currencies.length; i++) {

           //                menuXml += "<Button Id='" + currencies[i].transactioncurrencyid + "' Command='" + command + "' Sequence='" + ((i + 1) * 10) + "' LabelText='" + currencies[i].currencyname + "' CommandValueId='" + currencies[i].transactioncurrencyid + "' />";

           //            }

           //            menuXml += "</Controls>";

           //            menuXml += "</MenuSection>";

           //            menuXml += "</Menu>";

           //        }

           //        if (currencies.length == 0) {

           //            formContext.ui.setFormNotification("For this OLE no more currencies are available.", "INFO", "change_currency_on_quote_notification_id")

           //        }

           //        if (menuXml != "") {

           //            commandProperties.PopulationXML = menuXml;

           //        }

           //    }.bind(this)

           //);

           //var response = await this.ExecuteHttpRequestSync("GET", "transactioncurrencies", querystring);

           var response = this.ExecuteHttpRequestSync("GET", "transactioncurrencies", querystring);

           if (response && response.value) {

               for (var i = 0; i < response.value.length; i++) {

                   currencies.push(response.value[i]);

               }

           }

           if (currencies.length > 0) {

               formContext.ui.clearFormNotification("change_currency_on_quote_notification_id");

               menuXml += "<Menu Id='rav.quote.ChangeCurrency.Menu'>";

               menuXml += "<MenuSection Id='rav.quote.ChangeCurrency.MenuSection' Sequence='10'>";

               menuXml += "<Controls Id='rav.quote.ChangeCurrency.Control'>";

               for (var i = 0; i < currencies.length; i++) {

                   menuXml += "<Button Id='" + currencies[i].transactioncurrencyid + "' Command='" + command + "' Sequence='" + ((i + 1) * 10) + "' LabelText='" + currencies[i].currencyname + "' CommandValueId='" + currencies[i].transactioncurrencyid + "' />";

               }

               menuXml += "</Controls>";

               menuXml += "</MenuSection>";

               menuXml += "</Menu>";

           }

           if (currencies.length == 0) {

               formContext.ui.setFormNotification("For this OLE no more currencies are available.", "INFO", "change_currency_on_quote_notification_id")

           }

           if (menuXml != "") {

               commandProperties["PopulationXML"] = menuXml;

           }

    The function ExecuteHttpRequestSync is calling the function ExecuteHttpRequest  which executes a XmlHttpRequest sync based on a parameter. The promise and await patterns are commented out. Flyout button is populated correctly When I change in the executehttprequestsync (not sync anymore) that it returns a promise the flyout button doesn't show currencies anymore and a loading message is showing. Or I am doing something wrong/miss something or it can't be done in populate function. Do you have other ideas. Thanks in advanced for thinking with me. Regards, Stefan Verheggen

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans