MENSEN MAKEN HET SUCCES

Dynamic and real-time action cues in Business Central

Always bothered that you have to refresh the page before the numbers in the action cues (task boxes) are correct? And what if the action cues could be displayed dynamically?

For a client in the food industry, I created a dynamic and real-time role center. The operators can leave the screen open and the screen is automatically updated and task cues appear only when they are needed.

I use background tasks and a technique called Re-enqueuing background tasks.

It works as follows:

First, I have a simple role center with 2 parts:

 

I work out only one part. The other part works on the same principle.

In the IncomingGoods actioncue, I have 10 cues defined. I can turn these off or on. Unfortunately, it is not possible to use a function or even an array for properties like Visible, StyleExpr, etc. But for the Caption of the trays, the numbers, etc. I do use an array. This array in my case is filled by the records of a table. I.e. define as many cues as you think you need at most.

Now in this page we are going to start the background task on the OnAfterGetCurrRecord. The EnqueueBackgroundTask command has as parameters a task id (which we will need again later) and the code unit we are running in the background. Finally, we specify a parameter with a Dictionary, in this case a Sleep of 1 millisecond.

What happens in the code unit? In the code unit, we do our calculations and populate the dictionary based on a table of records that we convert to an array for the planned production per item, for example. Or: TodoProd[1] = filled with the planned number of kg for the item in record 1. Every time the numbers of kg are filled for each item for planned, weighed and booked. 

If the values are greater than 0 then the Dictionary variable ShowCue (with sequence number) is filled with 'true', otherwise with 'false'.

With the command 'SetBackgroundTaskResults' we return the dictionary to the calling task (from the action cue).

Back to the IncomingGoods ActionCue page. We now need to start responding to the completion of the task. That's what we do with the trigger below where we check for the previously mentioned task id.

As mentioned, it is not possible to use an array for "Visible". This results in an error message 'client expression not allowed'. So we have to solve this by pre defining a number of variables for the maximum number of trays (10 in my case) which we also assign.

We make sure that, at the end of the trigger we do a "Re-enqueue" of the background task but now with a sleep of 60,000 making us wait one minute, after which the screen is updated. Should trays need to be turned off or on based on the data then this is done automatically, just as the numbers in the trays are automatically refreshed (every minute). I have tested with a roll center with 30 trays so perhaps there could be many more.

Of course, we also need to make sure that any errors in the background task are handled. We do that with the trigger "OnPageBackgroundTaskError.

 

That's it. Have fun!