All materials I found state that it is possible and Dataverse will itself manage returned Promise. But homepage grid doesn't show the button even if I leave "return true" at the function beginning. It looks like to be fast enough, so I guess it's not 10 seconds limit hit. The button doesn't show especially when there are selected records.
I use typescript and registered function on enable rule via Ribbon Workbench. Here's my code:
public static async showCustomButton(selectedControlSelectedItemIds: string[]): Promise<boolean> {
try {
if (!selectedControlSelectedItemIds?.length) {
return false;
}
var entityName = "timesheet";
var entityIdName = "timesheetid";
var submittedStatus = 1;
const response = await Xrm.WebApi.retrieveMultipleRecords<{ statuscode?: number }>(
entityName,
`?$select=statuscode&$filter=${selectedControlSelectedItemIds.map(id => `${entityIdName} eq '${id.replace(/[{}]/g, "").trim()}'`).join(" or ")}`
);
if (response.entities.length !== selectedControlSelectedItemIds.length) {
return false;
}
const allMatch = response.entities.every(e => e.statuscode === submittedStatus);
if (!allMatch) {
return false;
}
return true;
}
catch {
return false;
}
}
It was necessary to add "SelectionCountRule" with "Minimum = 1" to the enable rules