Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function request: GETCALLSTACK #2019

Closed
ptijsma opened this issue Apr 13, 2018 · 5 comments
Closed

New function request: GETCALLSTACK #2019

ptijsma opened this issue Apr 13, 2018 · 5 comments
Labels
suggestion This is either a suggestion of a completely new feature or a fairly big change request.

Comments

@ptijsma
Copy link

ptijsma commented Apr 13, 2018

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 :-(

@StanislawStempin StanislawStempin added the suggestion This is either a suggestion of a completely new feature or a fairly big change request. label Apr 16, 2018
@redIT-LoPf
Copy link

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

@atoader atoader added the debugger Issues related to the debugger label Aug 8, 2019
@ptijsma
Copy link
Author

ptijsma commented Jun 22, 2020

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.

@ernestasjuska
Copy link

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

@pborring pborring removed the debugger Issues related to the debugger label Mar 4, 2022
@pborring
Copy link
Contributor

pborring commented Mar 4, 2022

@pborring pborring closed this as completed Mar 4, 2022
@navdotnetreqs
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion This is either a suggestion of a completely new feature or a fairly big change request.
Projects
None yet
Development

No branches or pull requests

7 participants