Question

In Dymanics AX 4.0, I want to run some methods under the Application Object Tree (AOT) > Data Dictionary > Tables > CustTable > Methods. (Could be any table at all)

This is mainly to get some custom calculated values, and also in part to deal with SQL injection Axapta.ExecuteStmt - Is it safe?

I found AxaptaRecord.Call documentation here but it doesn't help alot. Not sure if it is the correct method too. Also, what are the method call differences in terms of function types? e.g. public, static, server, return value types etc.

Hoping for some advice. Thanks.

Was it helpful?

Solution 2

Those functions are intended to solve different problems in .NET that can easilly be solved from X++:

  • Axapta.ExecuteStmt is the way to send some SQL (on the X++ internal SQL syntax) to the database that can be a select, update_recordset, etc. Exactly the same functionallity and results that if you write SQL commands inside the X++ code.

  • AxaptaRecord.Call is a class method. That way, with this function you can only run record methods coded in X++ inside a table (those that can be found inside the Methods node on the AOT, like the usual .find() method).

EDIT: There is a third interesting method:

  • Axapta.CallStaticClassMethod is the way to execute an static method saved on a class. As the method needs to be static, you don't pass an object to the function, but just the class name and method name, as it is executed on a new context.

OTHER TIPS

There are a couple things to consider

  1. It looks like you're trying to call Axapta objects from .Net, so the easiest way is to use the Business Connectory (Microsoft.Dynamics.BusinessConnectorNet)
  2. Create a wrapper class with static methods that understand how to instantiate the buffers and do the calculations you want (static method means you don't have a record/buffer for that table instantiated)

It (could) look something like this

    Axapta ax = new Axapta();
    try
    {
        //Note this is getting UserId out of web.config for a web service
        ax.LogonAs(ConfigurationManager.AppSettings["uid"], "contoso.com", null, null, null, null, ConfigurationManager.AppSettings["config"]);

        string returnString = (string)ax.CallStaticClassMethod("WrapperClassName", "StaticMethodName", _parameterPassedToMethod);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top