Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Async EnableRule for Ribbon blocks rendering

Posted on by 5

We have an EnableRule (JS) for a ribbon button. Because it calls an api, it takes a bit and hence, should be async. The following implementation ilustrates the problem:

export async function ribbonEnabled():Promise<boolean> {
   setInterval(() => {console.log(new Date().toLocaleTimeString())}, 1000);
   await new Promise(r => setTimeout(r, 7000));
   console.log('sleep is over');
   return true;
} 

Even tough the function is declared as async and awaits the api call (or in the example the timeout), the ribbon is not rendered until a value is returned.

Here you can see that several seconds have passed and no ribbon is rendered: 

5504.png

And as soon as the await procedure is over, the message gets printed and the ribbon is rendered:

7674.png

Is that a known issue? Are there any workarounds? I have seen solution where the function is synchronous, returns a boolean variable and in a promis changes this variable and calls ui.refreshRibbon. But this is not adviced and runs the whole function again, so more logic is needed.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Async EnableRule for Ribbon blocks rendering

    Hello,

    You can use the approach I used before Promise pattern was provided - butenko.pro/.../

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans