When you execute long-running tasks, such as generating a large report or posting many documents in one batch, this blocks the user interface, forcing the user to wait until the task completes. Such extensive tasks can be run as background sessions, while the UI remains responsive.
This recipe shows how to run a batch job in a background session. The code in the recipe starts a session that posts sales and purchase invoices:
Create a codeunit 50019 Post Invoices.
In the
OnRun
trigger, declare the following local variables:Name
DataType
Subtype
SalesHeader
Record
Sales Header
PurchaseHeader
Record
Purchase Header
SalesPost
Codeunit
Sales-Post
PurchPost
Codeunit
Purch.-Post
Enter the
OnRun
trigger code as follows:WITH PurchaseHeader DO BEGIN SETRANGE("Document Type","Document Type"::Invoice); IF FINDSET THEN REPEAT Receive := TRUE; ...