Using the Cross company feature from the Business Connector.

In Ax 2009 the new cross company feature was introduced. It allows the programmer to specify a container containing strings denoting company names to the crosscompany hint:

container c = [‘dat’, ‘dmo’];
select crosscompany: c * from custtable where custtable.Name == “Jones”;

That is all very well in X++, of course, but how do you handle it when accessing data through the business connector?

The first approach would be to do something like the following:

AxaptaRecord r = axapta.CreateAxaptaRecord(“CustTable”); 
ax.ExecuteStmt(“select crosscompany: [‘dmo’, ‘dat’] * from %1 where %1.Name == ‘Jones'”, r);

However, that will not work: The argument to the crosscompany hint is not an expression of type container, it is a variable of type container. Hence you cannot provide arbitrary expressions, only variable references. This was done to make the implementation of the feature simpler.

The solution lies in the realization that the string that enters the ExecuteStmt is actually entered into a function that is compiled and executed at runtime. There are no limits to what can be expressed in this string, as long as it is legal X++ statements.

So, consider doing:

AxaptaRecord r = axapta.CreateAxaptaRecord(“CustTable”); 
ax.ExecuteStmt(“container c = [‘dmo’, ‘dat’]; select crosscompany: c * from %1 where %1.Name == ‘Jones'”, r);

which would actually work.




Comments (1)

  1. wenni057 says:

    Hi Peter,

    is it posible to make join with the ExecuteStm,

    I tried this "SalesTable st; select * from %1 join st where %1.accountnum == st.custaccount" but it did not work out.