Business Central 2025 wave 1 (BC26): Get the current callstack (SessionInformation Data Type)

Dynamics 365 Business Central

Hi, Readers.
Dynamics 365 Business Central 2025 wave 1 (BC26) is generally available. More details: General Available: Dynamics 365 Business Central 2025 release wave 1 (BC26).

I will continue to test and share some new features that I hope will be helpful. In this post, I would like to talk about how to get the current callstack in AL.

This new feature is not yet documented in the Business Central 2025 release wave 1 (BC26) release plan but is mentioned in AL Language extension changelog Version 15.0

Added support for getting the current callstack by using the following statement callstack := SessionInformation.Callstack.

https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

A call stack is a chain of function calls that have led to the current location of the program counter. The top function on the call stack is the current function being executed, while the next function is the one that called the current function, and this continues down the stack. Each thread has its own call stack, which represents the calls made in that thread. First let’s take a quick look at the usage in BC so far.

1. During debugging, you can check it in the CALL STACK.

Copy Call Stact:

TestNoEntriesExist (\BC26P\Table\27\Item.dal:2633)
Item Tracking Code – OnValidate (\BC26P\Table\27\Item.dal:1722)

2. Using a performance profiling editor view in the AL Visual Studio Code extension, developers can then investigate the time spent on execution, either using top-down or bottom-up call stack views. More details: Business Central 2021 wave 2 (BC19): Profiling AL performance with snapshot debugger (AL: Generate profile file)

PS: Starting with Business Central 2022 wave 1 (BC20), this is also available in the Performance Profiler feature in the web client.More details: Business Central 2022 wave 1 (BC20) new features: In-client performance profiler (Performance Profiler page)

3. Using System.GetLastErrorCallStack() Method: Gets the call stack from where the last error occurred.

Item(Table 27).TestNoEntriesExist line 14 – Base Application by Microsoft
Item(Table 27).”Item Tracking Code – OnValidate”(Trigger) line 20 – Base Application by Microsoft

PS: There are also ErrorInfo.Callstack() Method and Using the AL call stack, etc., which I will not introduce one by one this time.

With this wave (BC26), Microsoft has added a new method to SessionInformation Data Type to get the current callstack, SessionInformation.Callstack() Method.

Syntax: Callstack := SessionInformation.Callstack()

Return Value: Text (The current callstack)

Let’s look at a very simple example.

As with System.GetLastErrorCallStack() Method, this includes the object name(object type + object number).method or trigger name + line number – extension name by publisher

CustomerListExt(PageExtension 50100).OnOpenPage(Trigger) line 2 – BC26P by YUN ZHU

Another simple example:

When I click post on the Sales Order page:

If you look from the bottom up, this is a complete code drilling process:

“Sales Order”(Page 42).”Post – OnAction”(Trigger) line 2 – Base Application by Microsoft
-> “Sales Order”(Page 42).PostSalesOrder line 10 – Base Application by Microsoft
-> “Sales Header”(Table 36).SendToPosting line 18 – Base Application by Microsoft
-> “Sales-Post (Yes/No)”(CodeUnit 81).OnRun(Trigger) line 10 – Base Application by Microsoft
-> “Sales-Post (Yes/No)”(CodeUnit 81).Code line 25 – Base Application by Microsoft
-> “Sales-Post (Yes/No)”(CodeUnit 81).RunSalesPost line 12 – Base Application by Microsoft
-> “Sales-Post”(CodeUnit 80).OnRun(Trigger) line 2 – Base Application by Microsoft
-> “Sales-Post”(CodeUnit 80).RunWithCheck line 16 – Base Application by Microsoft
-> “Sales-Post”(CodeUnit 80).OnBeforePostSalesDoc(Event) line 2 – Base Application by Microsoft
-> MyCodeunit2(CodeUnit 50113).”Sales-Post_OnBeforePostSalesDoc” line 2 – BC26P by YUN ZHU

So this is very useful when investigating code problems, as well as performance issues.

PS: A similar method is also added in codeunit 28 “Error Message Management”
codeunit 28 “Error Message Management” -> GetCurrCallStack

In addition to the information obtained in SessionInformation.Callstack() Method, there is also a app version number at the end. For example,

Great. Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL