Hello,
I am trying to enable/display a smart button on the main gird (view) of a table (entity).
I want it to be enabled if the selected row has certain criteria met.
I found that when using the value rule in the ribbon workbench this only works if the grid (view) has all the columns (fields) in the condition.
I tried to use a custom enable rule using the following code but it will not return the true value back to ribbon workbench to enable the button
CheckForecastView: function (selectedItems) {
var gridContext = selectedItems[0].Id;
var retVal = false;
Xrm.WebApi.retrieveRecord("msdyn_customerasset", gridContext, "?$select=a, b, c").then(
function success(result) {
var a = result.a;
var b = result.b;
var c = result.c;
if(a !== 809700000 && b !== 1 && (c === "SA" || c === "SA13")) {
retVal = true;
}
else {
retVal = false;
}
return retVal;
});
},
Bipin,
This worked.
Thank you very much!
Regards,
Patrick Nielsen
Hi,
Your code is working but it is not returning the correct result because XRM.WebApi.retrieveRecord executes as async process. You will need to use promise to evaluate the ribbon rule. Please see below blog -
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148