Wednesday, November 25, 2009

Kernel functions exposed through BC.NET

BC.NET is a great feature of Dynamics AX. It allows to access the AX application from any external application that supports .NET, and provides a rather rich functionality out of the box.
But one feature that is missing in BC.NET is the ability to call AX kernel functions, like fieldId2Name, num2str, decRound, etc.

I needed to use these functions in my code recently, and in order to access them, I created a class in X++, that simply wraps the useful functions in static methods, kinda like the ones that exist in class Global.

Download Class_KernelFunctions.xpo

You need to import it into AX before using, of course. This can be automated, if you don't want to include this XPO as part of the package you deliver to your customers.

Now you can call it through the Business Connector the following way:

Axapta ax = new Axapta();
ax.Logon("ext", null, "localhost", null);
// num2str(123.45, -1, 2, 1, 1);
Convert.ToDouble(ax.CallStaticClassMethod("KernelFunctions", "num2str", 123.45m, -1, 2, 1, 1));