Dynamics 365 Business Central – how to use timers in AL

When still working in Dynamics NAV, you can easily add a timer to your page to allow, for instance, refreshes of the page in intervals. For that, you could use a Control Add-In called “Ping Pong”. Since we have no ability to use .Net anymore in AL, this ability went away and was not replaced with anything new yet.

While we have suggested already a different implementation to make this functionality available on all pages by default, it is not decided, if anything will be done. So, for now, we are stuck without the ability to update the page content on a periodic basis.

We can, however, create our own user control and rewrite the Ping Pong functionality. It only takes a few minutes to do:

Create a new user control in your project:

Then add a new folder called “js” and place two new files in the folder.

File 1: MyPingPongMain.js:

File 2: MyPingPong.js

That’s it. Now you can add the user control to any page, as seen below in a page extension

You will see that you will get a message shown every 2 seconds (the timer interval is in milliseconds). It is important to stop the timer when the timer has elapsed (trigger TimerElapsed) so that the timer is not trying to raise a new event while the message is still shown.

Obviously, you can add any code you want in the body of the TimerElapsed trigger.

 

This code does not have extensive error handling and is not quality controlled. You are going to use this code as a sample only and at your own risk. Support is not provided for this user control.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.