Page Background Tasks in Microsoft Dynamics 365 Business Central 2019 release wave 2 continued..

Hi All,

A page background task is a child session that runs processes from a codeunit in the background, letting the user continue working on the Parent page session while the task runs. 

If you are new to PAGE Backgroung Task for basic understanding you can refer Page Background Tasks in Microsoft Dynamics 365 Business Central 2019 release wave 2

Let understand this by taking an AL Code example.

Customer has a requirement to display the Count of Posted Sales Invoice for a Customer on Customer card.

This can be done in 2 steps.

  1. Create Page Background Task on Page:
  2. Create a background task codeunit.

Create Page Background Task on Page

We will first create Page Extension for Customer Card.

We will add a Text Var to display “Posted Sales Invoice Count” on Customer card and add the same in General Tab .

Customer Card Ext for Page Background Task in MSDYN365BC.

Add EnqueueBackgroundTask

When a page background task is enqueued, parameters are passed as a dictionary of text to the codeunit’s OnRun trigger when the page background task session is started.

EnqueueBackgroundTask in Msdyn365bc

OnPageBackgroundTaskCompleted Trigger

OnPageBackgroundTaskCompleted trigger of the page in the parent session is called, and the results of the task are passed to the trigger. The results are passed as a dictionary of text.

OnPageBackgroundTaskCompleted in Msdyn365bc

OnPageBackgroundTaskError Trigger

When an error occurs in the page background task codeunit, this trigger of the page in the parent session is automatically called and we need to handle the error.

OnPageBackgroundTaskError in Msdyn365bc

Create a background task codeunit.

You need to create a new codeunit which will do all the calculation and run it in background. After the calculation have been performed the it needs to be passed back to the calling page for handling through SetBackgroundTaskResult and get data from Parent session through GetBackgroundParameters .

PageBackgroundTask Codeunit in Msdyn65bc

This was complete overview of the process. You can try this and improve the performace of the pages.

You can download the code from GIT.

For more details you can read Best Practices for AL Coding in Microsoft Dynamics Business Central (MSDYN365BC)

To get new updates and learn about Microsoft Dynamics 365 Business Central Microsoft Learn

Thanks for reading.

One thought on “Page Background Tasks in Microsoft Dynamics 365 Business Central 2019 release wave 2 continued..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s