Microsoft Dynamics® AX 2009: How to Call AX 2009 from an External Application and Open a Specific Form/Record

image

(This post courtesy of Natalia Efimtseva)

Recently I worked with my colleague, Max Belugin, who is an expert in Dynamics. We were solving one interesting question—how you can activate and open a specific AX 2009 form/record from an external application or code.

You can use following approaches to open AX from an external environment:

1. COM API

Unfortunately, at the current moment .NET Business Connector doesn’t implement UI function, and thus it is not possible to open a specific AX form. But we can register AX32.EXE as a COM Object.

 static void Connect(string[] args)
 {
 AxClientLib.DynamicsAxApplication dynamicsClient;
 try
 {
 //find running Ax32.exe
 dynamicsClient = (AxClientLib.DynamicsAxApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("Dynamics.Application");
 }
 catch      
 {
                //Launch new Ax32.exe
 dynamicsClient = new AxClientLib.DynamicsAxApplicationClass();
 }
  
 if (dynamicsClient != null)
 {
 //Run form
 dynamicsClient.OpenMenuItem("DMO", "SalesTable", AxClientLib.AxMenuType.DisplayMenu);
 }
 }

Note: API doesn’t really call “form open,” but rather calls a Menu Item associated with a form. So you can call a specific form in this way, but not a specific record.

2. SysStartupCmd

You can also run a command when an Application Object Server (AOS) instance starts (details).

You need to:

  • Add your startup command to the switch in Classes\SysStartUpCmd\construct statement (given your startup statement is FormXX).
 case 'FormXX':
 return new SysStartupCmdFormXX(s,parm);
  • Create a new class SysStartupCmdFormXX.
 class SysStartupCmdFormXX extends SysStartupCmd
 {
 }
  • Override the method applInit in this class.
 void applInit()
 {
 Args args;
 FormRun formRun;
  
 args = new args(formstr(FormXX));
 formRun = classFactory.formRunClass(args);
 formRun.init();
 formRun.run();
 formRun.detach();
 }

This guidance is taken from here—so you can implement your own desired behavior of AX.

3. AxPath

AxPath is a protocol for activating Axapta forms. It does the following:

  • It sits on a timer event and polls the queue.
  • When it finds that there are some commands for the queue, it executes them.

There is an external part named "URL handler," which takes an URL and places it in the queue. The queue is implemented using shared memory.

So, for example, when you click in the browser in URL like:

AxPath://MenuItem/Display/EmplTable?Area=dat&RecID=1032355

The following actions are performed:

  1. Browser executes an URL handler with the URL as a command-line parameter.
  2. URL handler puts that URL into the queue.
  3. When the Tabax plugin polls the queue and detects that the URL is present, it opens the EmplTable menu item and navigates to  the particular employee.

With this method, you can open a specific form as well as a specific record.

4. EventDrillDown

This approach is based on alerts and notification capabilities of Axapta and named pipe protocols. External drill-down is the ability to initiate and use the AX drill-down feature from a program external to AX. This means you can open a specific form as well as a specific record.

Please refer this link for more details and source code for this method.