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