AL icon indicating copy to clipboard operation
AL copied to clipboard

New function request: GETCALLSTACK

Open ptijsma opened this issue 8 years ago • 6 comments

I've posted it on Yammer on November 1st, 2017, but not sure if anyone seen it. (see https://www.yammer.com/dynamicsnavdev/#/Threads/show?threadId=974473209)

I would like to vote for a new function, accessible from AL called GETCALLSTACK. The function should be similar to GETLASTERRORCALLSTACK, but then accessible whenever needed, without throwing an Error first.

When using events, it would be very benificial to find out from where the event was originated through the callstack. My current solution (fully .Net based in C/AL) will of course not work anymore in AL.

image

And using a TryFunction with explicit Error and then GETLASTERRORCALLSTACK is not the right way to go from my opinion.

Even worse: It's not even allowed anymore to use TryFunctions in AL, so there's not even an alternate solution right now :-(

ptijsma avatar Apr 13 '18 13:04 ptijsma

We are looking too for a possibilty to get the callstack. A command like requested would be very helpful.

redIT-LoPf avatar May 07 '18 05:05 redIT-LoPf

Any news on this issue? & @atoader : Didn't see it until now, but why is it marked with a "debugger" tag? The idea is to to be able to use it during normal code execution, not when debugging.

ptijsma avatar Jun 22 '20 12:06 ptijsma

Hi, I can also add that there is a platform function like that and it is used for GetLastErrorCallStack().

In assembly Microsoft.Dynamics.Nav.Ncl.dll there is an internal function NavSession.GetCurrentCallStack(). I used it through an add-in to log call stacks when logging record changes.

using Microsoft.Dynamics.Nav.Runtime; // need to reference Microsoft.Dynamics.Nav.Ncl.dll
using System;
using System.Reflection;

namespace NavCallStack
{
    public class NavCallStack
    {
        public string GetCurrentCallStack()
        {
            MethodInfo methodInfo =
                typeof(NavSession)
                .GetMethod(
                    "GetCurrentCallstack", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(Func<NavApplicationObjectBase, string>) }, null);
            if (methodInfo == null)
                throw new NullReferenceException("Could not find method NavSession.GetCurrentCallstack(Func<NavApplicationObjectBase, string>).");
            return (string)methodInfo.Invoke(NavCurrentThread.Session, new object[] { new Func<NavApplicationObjectBase, string>(a => a.ObjectName) });
        }
    }
}

Example output:

"My Call Stack Demo"(CodeUnit 50100)."(Page Call Stack Demo) MyEvent" line 4 - CallStackDemo by Default publisher
"Call Stack Demo"(Page 50100).MyEvent(Event) line 2 - CallStackDemo by Default publisher
"Call Stack Demo"(Page 50100).OnOpenPage(Trigger) line 2 - CallStackDemo by Default publisher

ernestasjuska avatar Sep 10 '21 09:09 ernestasjuska

Closing, tracked in idea https://experience.dynamics.com/ideas/idea/?ideaid=84d8ed18-5a7f-ec11-b820-0003ff45920b

pborring avatar Mar 04 '22 14:03 pborring

Still relevant and should be simple enough to implement since it already exists, just not available..

navdotnetreqs avatar Apr 12 '24 19:04 navdotnetreqs

It is now possible using command SessionInformation.Callstack https://yzhums.com/63662/

ViktorasDanielius avatar May 02 '25 08:05 ViktorasDanielius