SessionInformation.Callstack() in Business Central

Introduced in Business Central Wave 1 2025 releases, the SessionInformation.Callstack() method is a powerful diagnostic tool that helps developers trace the current call stack within AL code. Whether you’re troubleshooting custom extensions, tracking errors, or building telemetry, this method can become your best friend.

What is the SessionInformation.Callstack() Method?

The SessionInformation.Callstack() method is a built-in function in AL that returns a text string representing the current call stack of the Business Central server session. Think of the call stack as a chronological list of the functions and procedures that have been called to reach the current point in your code.

Each entry in the call stack typically includes:

  • Object Type and Name: The type of object (e.g., Codeunit, Table, Page) and its name.
  • Function/Procedure Name: The specific function or procedure being executed.
  • Line Number: The line number within the function/procedure where the call originated.

📌 Syntax

var
    CallStackText: Text;
begin
    CallStackText := SessionInformation.Callstack();
end;

🧩 Why is the Call Stack Important?

Understanding the call stack is crucial for several reasons:

  • Debugging: When an error occurs, the call stack provides a trace of the execution path leading up to the error. This helps you pinpoint the exact location where the issue originated and understand the sequence of events that triggered it.
  • Error Handling: By capturing and logging the call stack when an error occurs, you can provide more context to administrators or support teams, making it easier to diagnose and resolve issues.
  • Code Understanding: Analyzing the call stack can help you understand the flow of execution in complex codebases, especially when working with unfamiliar code or trying to understand how different modules interact.

You can combine this with

  • ErrorInfo object (for AL error handling)
  • SessionInformation.UserId() or CompanyName() for full diagnostic logs
var
    CallStack: Text;
    ErrorData: ErrorInfo;
begin
    if not TryMyFunction() then begin
        GetLastError(ErrorData);
        LogToTable('Error: %1 - Stack: %2', ErrorData.Message, SessionInformation.Callstack());
    end;

SessionInformation.Callstack() is a small method with big potential. It’s the AL developer’s X-ray — revealing the path of execution in complex customizations or tangled logic.

Use it smartly, especially in:

  • Error handling routines
  • Long-running jobs
  • Telemetry and diagnostics pipelines

Stay Tuned for more updates

Introduction of ‘Continue’ in Business Central v26

The Dynamics 365 Business Central ecosystem is in a state of continuous evolution, with each release bringing enhancements that empower developers and refine business processes. With the advent of version 26 (2025 release wave 1), a particularly noteworthy addition to the AL programming language is the continue statement. While seemingly a minor syntactic change, its implications for code efficiency and clarity are substantial.

A Refined Approach to Loop Control

In the realm of business application development, loops are indispensable. They facilitate iterative data processing, automation of repetitive tasks, and the implementation of complex algorithms. However, traditional loop structures often necessitate convoluted conditional logic to bypass specific iterations, leading to code that is both verbose and difficult to maintain.

The introduction of continue addresses this challenge directly. By providing a concise mechanism to skip the remaining code within a loop’s current iteration and proceed to the next, it promotes a more streamlined and readable coding style.

Benefits for Business Central Developers

  • Enhanced Code Readability: The continue statement reduces the reliance on nested IF statements, resulting in cleaner and more maintainable code. This is particularly crucial in large-scale Business Central implementations where code clarity is paramount.
  • Improved Performance: By bypassing unnecessary code execution, continue contributes to optimized loop performance. This is especially relevant when processing large datasets or executing computationally intensive operations.
  • Modernization of AL: The inclusion of continue aligns AL with contemporary programming paradigms, enhancing its usability for developers accustomed to other languages. It signifies changes to evolving AL into a more robust and versatile development platform.
  • Increased Development Flexibility: The ability to finely control loop execution grants developers increased flexibility when coding. This allows for more complex and efficient algorithms to be developed.

Where Can You Use ‘Continue’?

The continue statement is your ally within various loop structures in AL:

  • for loops: Ideal for iterating a specific number of times.
  • while loops: Perfect for looping until a condition is met.
  • repeat...until loops: Useful for executing a block of code at least once.
  • foreach loops: Designed for iterating through collections.

A Case in Point

Consider a scenario where a developer needs to process a batch of sales orders, excluding those with specific characteristics. Without continue, the code might involve nested IF statements to filter out unwanted orders. However, with continue, the logic becomes significantly more concise:

local procedure ProcessSalesOrders(SalesOrderRecord: Record "Sales Header")
begin
    SalesOrderRecord.Reset();
    SalesOrderRecord.FindSet();

    repeat
        if SalesOrderRecord."Order Type" = SalesOrderRecord."Order Type"::Quote then
            continue; // Skip quotes
        end;

        // Process the remaining sales order logic here
        // ...
    until SalesOrderRecord.Next() = 0;
end;

This example illustrates the power of continue in simplifying loop logic and enhancing code clarity.

Stay tuned for more.