I am new to AX. I have done a few simple things using C# and the .Net business connector. Now I want to fetch some data from AX using a SQL statement with several joins. But I don’t know how to do this. ALl the examples I find only use one table. Not sure how to tell AX that I am using 5 tables. Here is what I have so far:
Axapta
ax = new Axapta();
AxaptaRecord axRecord;
string tableName = “InventTable”;
ax.Logon(
“”, “”, “”, “”);
string strSQL = @“SELECT DISTINCT ITEMNAME, PT.ATTRIBUTEDESC As PackageType, PS.ATTRIBUTEDESC As PackageSize, PD.Amount AS UnitPrice, UC.Factor AS CasesPerPallet FROM INVENTTABLE IT LEFT JOIN WFSPACKAGETYPE PT ON IT.WFSPACKAGETYPEID == PT.PACKAGETYPEID && IT.DATAAREAID == PT.DATAAREAID LEFT JOIN WFSPACKSIZE PS ON IT.WFSPACKSIZEID == PS.PACKSIZEID && IT.DATAAREAID == PS.DATAAREAID LEFT JOIN PRICEDISCTABLE PD ON IT.ITEMID == PD.ItemRelation && IT.DATAAREAID == PD.DATAAREAID LEFT JOIN UNITCONVERT UC ON IT.BOMUNITID == UC.FROMUNIT && IT.ITEMID == UC.ITEMID && IT.DATAAREAID == UC.DATAAREAID WHERE IT.DATAAREAID == '” + company + “’” + " && IT.ITEMID == ‘" + ddlItem.SelectedValue + "’" + " && PD.AccountRelation == ‘" + Convert.ToString(Session[“CustAcct”]) + "’";
DataRow drItem = dtItems.NewRow();
using (axRecord = ax.CreateAxaptaRecord(tableName))
{
axRecord.ExecuteStmt(strSQL);
DataRow drItem = dtItems.NewRow();
drItem[
“ItemName”] =
Convert.ToString(axRecord.get_Field(“ItemName”));
drItem[
“PackageSize”] =
Convert.ToString(axRecord.get_Field(“PackageSize”));
drItem[“PackageType”] = Convert.ToString(axRecord.get_Field(“PackageType”));
}
I have more fields but I simplified it. When I run this, I get an error on the ExecuteStmt. The error is:
Unable to compile
My first question is how do I specify more than one table? I specify my main table in a string variable like this:
string tableName = “InventTable”;
I then create the AX record using this line"
using (axRecord = ax.CreateAxaptaRecord(tableName))
But how do I define my other 4 tables that I am joining?
Can anyone give me an example that shows how to do this?
Thanks,
Bob