web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Blogs by Yash / Run Async Functions in Busi...

Run Async Functions in Business Central: StartSession()

Yash_Mistry Profile Picture Yash_Mistry 512
Hi Readers,

Today I would like to briefly share one useful AL method that many developers should know when working with long-running processes in Business Central StartSession().

This method helps us run code in the background without making users wait on the screen.

What is StartSession()?

Session.StartSession() creates a new session and runs a Codeunit asynchronously.

That means:
  • Current user can continue working
  • Heavy process runs in background
  • Better performance experience
  • Useful for integrations and bulk processing

Basic Syntax

Session.StartSession(SessionId, Codeunit::"Async Sessions");

Where Can We Use It?

  • API Calls
  • Data Synchronization
  • Bulk Record Updates
  • Email Sending
  • Background Validations

Example:
Page Action

action("Call Async Session")
{
    ApplicationArea = All;
    Promoted = true;
    Image = Start;

    trigger OnAction()
    var
        SessionId: Integer;
    begin
        //Start Async Session and Returns Session ID
        Session.StartSession(SessionId, Codeunit::"Async Sessions");

        Message('Async Session Started: %1', SessionId);
    end;
}

Codeunit

codeunit 50100 "Async Sessions"
{
    trigger OnRun()
    begin
        // Your long running process here
    end;
}

Benefit Here:

  • User can continue work immediately
  • API delay does not block screen
  • Better productivity

Important Note

You do not need to manually close the session.

Business Central automatically ends it after completion.

Final Thoughts

If you are building integrations or heavy custom processes in Business Central, StartSession() is a very useful method.

It improves performance, user experience, and scalability.


Hope this helps.
Thanks for reading.

Yash Mistry.

Comments