Code highlighting

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));


  1. Hi,
    I know is a bit ridiculous the following question, but there is any way with BC to do:

    dictClass.callObject('test', AXObject); ?

    So that I call a method of an instance object in AX from BC.

    Mariano Vicario

  2. Yes. I have shown an example in one of my previous posts about BC.NET:

    You don't need the dictClass for that.

    AxaptaObject journalCheckPost = ax.CallStaticClassMethod("InventJournalCheckPost", "newPostJournal", header) as AxaptaObject; // You can object methods the same way you would on a table journalCheckPost.Call("parmShowInfoResult", false); journalCheckPost.Call("parmThrowCheckFailed", true); journalCheckPost.Call("parmTransferErrors", false);

  3. I think I didn’t expose correctly my problem. My idea is to instance an object in AX. Send it to a .net method, and with BC call a method of this Ax object. of course the following example does not work.



    TestClass p;
    p= new TestClass();


    class Functions
    static void Test(object obj)
    Axapta ax = new Axapta();
    ax.Logon("ext", null, "localhost", null);
    AxaptaObject dictclass = ax.CreateAxaptaObject("DictClass");
    dictclass.Call("callObject", methodname, obj);

    Mariano Vicario

  4. Nope, that's not currently possible.
    The session is different, so the object reference is illegal.

    I think that in the latest AX release there are plans to make this possible, but I am not certain.

    In order to do this, you will have to create the TestClass ax object from BC.NET like the DictClass you do in the example above

  5. Hi,
    one more question please :)
    I have AOS in one PC, and the clients on others PC. I have install on the aos server a dll on the GAC. Then I open the AOT on the client, and I add the reference in AX. But it dosent works, it dosent compile. If I install this dll on each client it works fine. There is any way to only install a dll on the AOS???

    Mariano Vicario

  6. Here is a reply I got to your question on one of the internal discussion formus:

    The Assembly has to be in the GAC or under the Client\Bin folder, in order to be able to compile any X++ code using the types defined in your assembly. That is because the X++ compilation process runs on the client, and that is independent from what happens at runtime.

    From runtime perspective if the assembly is going to be used by code (X++) running on the server, then the assembly has to be in the GAC or under Server\Bin.

    In other words, for X++ compilation the assembly has to be in the Client machine GAC or under Client\Bin.
    For runtime the Assembly has to be in the server machine GAC or under Server\Bin.


Please don't forget to leave your contact details if you expect a reply from me. Thank you