Tuesday, 18 June 2013

How to debug the X++ code that is running in AIF in Microsoft Dynamics AX

To debug the X++ code that is running in AIF, follow these steps:
1.       Enable the X++ debugging feature in Microsoft Dynamics AX 4.0. To do this, follow these steps:
a)       On the Tools menu, click Options.
b)      In the Options dialog box, click the Development tab.
c)       In the Debug mode list, click When Breakpoint.
d)      Click Apply, and then close the Options dialog box.
2.       Start the Microsoft Dynamics AX Configuration utility.
3.       In the Configuration target list, click Business Connector.
4.       On the Developer tab, click to select the Enable user breakpoints to debug code running in the Business Connector check box.
5.       Click OK, and then close the Microsoft Dynamics AX Configuration utility.
6.       Manually start the debugging feature. To do this, point to Development tools on the Tools menu, and then click Debugger.

Note The .Net Business Connector component cannot automatically start the debugging feature. Therefore, you must manually start the debugging feature.
7.       Click Application Object Tree.
8.       Expand Classes, expand AifOutboundProcessingService, and then double-click processAsUser.
9.       In the \Classes\AifOutboundProcessingService - Editor dialog box, set the character of theprocessAsUser method to public.
10.    Double-click run.
11.    In the \Classes\AifOutboundProcessingService - Editor dialog box, change the code as follows.

Existing code
12. ...
13. //Switches to the context of the user who submitted this request
14. //Also switches to the company under which the request was
15. //submitted.
16. // BP deviation documented
17. runas(outboundProcessingQueue.SubmittingUserId,
18. classnum(AifOutboundProcessingService),
19. staticmethodstr(AifOutboundProcessingService, processAsUser),
20. [outboundProcessingQueue], outboundProcessingQueue.Company);

Replacement code
//Switches to the context of the user who submitted this request
//Also switches to the company under which the request was
// BP deviation documented
// runas(outboundProcessingQueue.SubmittingUserId,
// classnum(AifOutboundProcessingService),
// staticmethodstr(AifOutboundProcessingService, processAsUser),
// [outboundProcessingQueue], outboundProcessingQueue.Company);

21.    Set a breakpoint in the AxdBase.validateEntityKey method.

Note You can set breakpoints in other methods that you want to debug.

22.   Run the AifOutboundProcessingService service as a service or as a batch.

Note After you complete this step, the validateEntityKey method can be broken to debug.