Quick Modification for Tracing Bug Code in a Dynamics AX Production Environment

By Bill Thompson | April 11, 2018

Quick modification for tracing bug code in a dynamics ax production environment

This quick modification for tracing bug code in a Dynamics AX production environment was used at a client site. I have received their permission to blog about this as I thought it was pretty useful.

Basically, the modification consists of the creation of an empty security role. When a user reports a bug, they may be asked for more detailed repro steps within the production environment. The user will be added to this security role, which will trigger the dumping of the X++ call stack into the Infolog when the error is generated. Once the repro is complete, the user is simply removed from the security role, and the logging is stopped. For the bug repro, the user may need to have running code in CIL disabled so the full call stack can be retrieved as well.

Part 1. Create an empty security role in the system

  • Navigate in the Dynamics AX 2012 client System administration > Setup > Security > Security roles
  • Click the New button
  • Fill in pertinent information

Create an empty security role in the system

  • Click the Close button

Part 2. Modify the info class, add() method

Change the method to the following code (no changes in the latter half of the method, so just make the displayed modifications:

Exception add(
    Exception _exception,
    str _txt,
    str _helpUrl = '',
    Object _sysInfoAction = null,
    boolean buildprefix = true)
    int numOfLines,i;
    int actionClassId;
    container packedAction;
    xSession session;

    // START - Add callstack to infolog 

    System.Diagnostics.StackTrace   myStackTrace;

    container                       myCallStack;
    int                             cntr;
    str1260                         whatToWrite;
    SecurityUserRole                securityUserRole;
    SecurityRole                    securityRole;
    boolean                         dumpCallStack = false;

    while select AotName from securityRole
        join securityUserRole
        where securityUserRole.User == curUserId()
        && securityUserRole.SecurityRole == securityRole.RecId
        if (securityRole.AotName == #mySecurityRole)
            // if we find the security role, set our X++ call stack dump variable, and quit searching as we are done
            dumpCallStack = true;

    if (dumpCallStack)   
        // determine if running as native X++ or as IL code
        if (xSession::isCLRSession())       // IL code
            myStackTrace = new System.Diagnostics.StackTrace(true);

            _txt += ' - ' + myStackTrace.ToString();
            myCallStack = xSession::xppCallStack();
            for(cntr=1; cntr<=conlen(myCallStack); cntr++)
                whatToWrite += conpeek(myCallStack, cntr);
                if (cntr mod 2)
                    whatToWrite += '-Line: ';
                    whatToWrite += "\r\n";
            _txt += ' \r\n Call stack: ' + whatToWrite;

    // END - Add callstack to infolog

NOTE: there is a rough stub for capturing the CIL call stack as well.

Part 3. Add the security role to the user

Within the client, navigate System Administration > Common > Users. Select the user by double-clicking, and add the security role to the user by clicking the Assign roles button

Add the security role to the user

Click the OK button once the debugging role has been selected.

Part 4. If needed, disable running business logic in CIL

In the client, navigate File > Tools > Options > Development tab. Uncheck the Execute business operations in CIL checkbox

Disable running business logic in CIL

Click the Close button.

At this point, you should be able to run a process, and see the call stack in the Infolog when the error is generated.


Once this has been captured, simply go back into the user, and remove the debugging security role from the user. If the Execute business operations in CIL checkbox was modified, go back and correct that setting as well.

I hope that you find this useful, and it provides you something you can add to your ‘bag of tricks’ for debugging or troubleshooting any Dynamics AX issues.

Related Posts

Recommended Reading:

Manage U.S. Use Tax on Purchase Orders in Dynamics 365 Finance and Operations

  Managing sales tax requirements on your business purchase can be complicated, but Dynamics 365 Finance and Operations can help […]

Read the Article
5.19.22 Dynamics CRM

How to Write a Great Support Ticket in the Stoneridge Support Portal

Submitting a support ticket through the Stoneridge Support Portal is a quick and effective way to get assistance for any […]

Read the Article

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article
5.5.22 Dynamics GP

The Real Story about the Long-Term Future of Dynamics GP Support

I’ve seen a number of people put forward comment that Dynamics GP is going away and you have to get […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Financial Enhancements

The Dynamics 365 Businses Central 2022 Wave 1 Release has a lot of new and exciting features to help your […]

Read the Article
4.29.22 Dynamics GP

Dynamics GP Transaction Removals: Bank Reconciliation

  This is part 2 of a 3 part series on Dynamics GP Transaction Removals. These quick tips will hopefully […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!