Ok I will give my code.
AX Classes code:
public static QueryRun getData(boolean _check,int _start,int _length,str _sortCol,str _sortDir,str _purchId)
{
PurchTable purchTable;
VendInvoiceJour vendInvoiceJour;
VendInvoiceTrans vendInvoiceTrans;
Query query;
QueryRun qr;
QueryBuildDataSource qbds1,qbds2,qbds3;
QueryBuildRange qbr;
int totalRec;
externalPurchTableTmp ExternalPurchTableTmp;
FieldId sortCol;
TableId myTableId;
SortOrder mySortDir=_sortDir=='Ascending' ? SortOrder::Ascending : SortOrder::Descending;
str myTable;
query=new Query();
qbds1=query.addDataSource(tableNum(VendInvoiceTrans));
qbds2=qbds1.addDataSource(tableNum(VendInvoiceJour));
qbds3=qbds2.addDataSource(tableNum(PurchTable));
qbds2.relations(false);
qbds2.addlink(fieldNum(VendInvoiceTrans,InvoiceId),fieldNum(VendInvoiceJour,InvoiceId));
qbds3.relations(false);
qbds3.addlink(fieldNum(VendInvoiceJour,PurchId),fieldNum(PurchTable,PurchId));
if(_sortCol=="PurchId" || _sortCol=="InvoiceId" || _sortCol=="InvoiceDate" || _sortCol=="DeliveryDate" || _sortCol=="ItemId" || _sortCol=="ItemName")
{
myTable="VendInvoiceTrans";
myTableId=tableName2id(myTable);
sortCol=fieldName2id(myTableId,_sortCol);
qbds3.addSortField(sortCol, mySortDir);
}
else if(_sortCol=="InvoiceAmount" || _sortCol=="OrderAccount")
{
myTable="VendInvoiceJour";
myTableId=tableName2id(myTable);
sortCol=fieldName2id(myTableId,_sortCol);
qbds3.addSortField(sortCol, mySortDir);
}
else if(_sortCol=="PurchName")
{
myTable="PurchTable";
myTableId=tableName2id(myTable);
sortCol=fieldName2id(myTableId,_sortCol);
qbds3.addSortField(sortCol, mySortDir);
}
qbds3.firstOnly(_length);
if(_purchId!="null")
{
qbr=qbds3.addRange(fieldNum(VendInvoiceTrans,PurchId));
qbr.value(strFmt('(PurchId=="%1")',queryValue(_purchId)));
}
qr = new QueryRun(query);
totalRec= SysQuery::countLoops(qr);
qr.enablePositionPaging(true);
ExternalPurchTableTmp.clear();
qr.addPageRange(_start,_length);
return qr;
}
ASP.NET c# code..
public void ProcessRequest(HttpContext context)
{
GlobalClass Con = new GlobalClass();
string myId = context.Request.QueryString["purchId"];
string isortDir = context.Request["sSortDir_0"].ToString();
string search = context.Request["sSearch"];
string isortColumn = context.Request["iSortCol_0"].ToString();
string fromDate = context.Request["fromDate"].ToString();
string toDate = context.Request["toDate"].ToString();
int start =int.Parse(context.Request["iDisplayStart"]);
int length =int.Parse(context.Request["iDisplayLength"]);
string txtSortCol ="0";
DateTime InvoiceDated;
int filteredCount = 0;
int totalRec = 0;
List<listPurch> ListPurchTable = new List<listPurch>();
bcn.AxaptaRecord purchTable,vendInvoiceJour,vendInvoiceTrans;
bcn.Axapta axp;
bcn.AxaptaObject qr;
axp = new bcn.Axapta();
axp=Con.OpenConn();
if (isortColumn == "0")
{
txtSortCol = "PurchId";
}
else if (isortColumn == "1")
{
txtSortCol = "InvoiceId";
}
else if (isortColumn == "2")
{
txtSortCol = "InvoiceDate";
}
else if (isortColumn == "3")
{
txtSortCol = "InvoiceAmount";
}
else if (isortColumn == "4")
{
txtSortCol = "OrderAccount";
}
else if (isortColumn == "5")
{
txtSortCol = "PurchName";
}
else if (isortColumn == "6")
{
txtSortCol = "DeliveryDate";
}
else if (isortColumn == "7")
{
txtSortCol = "ItemId";
}
else if (isortColumn == "8")
{
txtSortCol = "DeliveryDate";
}
start = start + 1;
if (search.Length == 0)
{
search = "null";
}
qr =(bcn.AxaptaObject) axp.CallStaticClassMethod("GST_callPurch", "getData", true, start, length, txtSortCol, isortDir, search);
while(Convert.ToBoolean(qr.Call("next")))
{
purchTable = (bcn.AxaptaRecord)qr.Call("get", (int)axp.CallStaticClassMethod("Global", "tableName2Id","PurchTable"));
vendInvoiceJour = (bcn.AxaptaRecord)qr.Call("get", (int)axp.CallStaticClassMethod("Global", "tableName2Id", "VendInvoiceJour"));
vendInvoiceTrans = (bcn.AxaptaRecord)qr.Call("get", (int)axp.CallStaticClassMethod("Global", "tableName2Id", "VendInvoiceTrans"));
listPurch ListPurch = new listPurch();
ListPurch.PurchId = purchTable.get_Field("PurchId").ToString();
ListPurch.InvoiceId = vendInvoiceJour.get_Field("InvoiceId").ToString();
InvoiceDated = DateTime.Parse(vendInvoiceJour.get_Field("InvoiceDate").ToString());
ListPurch.InvoiceDate = InvoiceDated.Month + "-" + InvoiceDated.Day + "-" + InvoiceDated.Year;
ListPurch.InvoiceAmount = float.Parse(vendInvoiceJour.get_Field("InvoiceAmount").ToString());
ListPurch.OrderAccount = purchTable.get_Field("OrderAccount").ToString();
ListPurch.PurchName = purchTable.get_Field("PurchName").ToString();
ListPurch.DeliveryDate = purchTable.get_Field("DeliveryDate").ToString();
ListPurch.ItemId = fromDate;//vendInvoiceTrans.get_Field("ItemId").ToString();
ListPurch.ItemName = vendInvoiceTrans.Call("ItemName").ToString();
//totalRec = 200;
ListPurchTable.Add(ListPurch);
filteredCount++;
}
var result = new { iTotalRecords = filteredCount, iTotalDisplayRecords = totalRec, aaData = ListPurchTable };
JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(result));
}