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
- 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:
str _helpUrl = '',
Object _sysInfoAction = null,
boolean buildprefix = true)
// START - Add callstack to infolog
boolean dumpCallStack = false;
while select AotName from securityRole
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;
// 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
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
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.