0

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;
        }
    }
2
  • Naive question, have you tried Display rule instead of Enable rule ? Commented May 13 at 14:08
  • @ArunVinothPrecogTechnologies i don't see possibility of using custom function in display rules. I'll need to check user role in future too, so I guess I need exactly function Commented May 14 at 8:00

1 Answer 1

0

It was necessary to add "SelectionCountRule" with "Minimum = 1" to the enable rules

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.