Monday 7 August 2017

Debugging code in Dynamics 365 for Operations

This topic reviews how you can debug X++ code by using the debugging feature in Microsoft Visual Studio.
To debug X++ code, you use the debugger in Microsoft Visual Studio. The process is similar to the process that is used for any other application that is created in Visual Studio. For example, the standard tools for examining the application are available when your code is stopped at a breakpoint.

Debug your code

To debug X++ code, follow these steps.
  1. In Visual Studio, open the X++ code to debug.
  2. Find the line or lines where you want execution to stop, and set breakpoints in those lines. To set a breakpoint in a line, click in the left column of the code editor or press F9 while the cursor is on that line. A red dot indicates that a breakpoint has been set.
    Red dot
  3. Set a startup project and a startup object. Startup objects can be any form, any class that has the main method, or any menu item. You can set the startup object in the Properties pane for the project. Alternatively, right-click the element in Solution Explorer, and then click Set as Startup Object.
    Set as startup object
  4. On the Debug menu, click Start Debugging.
  5. In the application, perform the action that causes the code that you're interested in to run. Typical actions include opening a form. Processing stops at the breakpoints that you set.
    Run
  6. Use the tools in Visual Studio to examine the application. For example, you can hover over variables in the X++ code to see their values. You can also use commands on the Debug menu to step through the code. Additionally, tools such as the Autos pane in Visual Studio will show important information about the state of the application.
    Hover
    Another tool that is specific to Finance and Operations is the Infolog. Often, info()statements are added to code to log status messages while the application is running. You can view these Infolog messages directly in Visual Studio. On the View menu, click Infolog.
    Infolog
  7. After you've finished debugging the application, exit Finance and Operations . Visual Studio will exit debugging mode.

No comments:

Post a Comment