Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2009

static void GetRangeValueOfQuery(Args _args)
{

Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbd;
Bill_Table vendTable;
QueryBuildRange range;
int ct, i;
;

qbd = query.addDataSource(tablenum(Bill_Table));

queryRun = new QueryRun(query);

queryRun.prompt(); // To Prompt the dialog

ct = queryRun.query().dataSourceTable(tablenum(Bill_Table)).rangeCount();

for (i=1 ; i<=ct; i++)
{
range = queryRun.query().dataSourceTable(tablenum(Bill_Table)).range(i);
info(strfmt(“Range Field – %1, Value – %2”,range.AOTname(),range.value()));
}
range = qbd.addRange(fieldnum(Bill_Table,ItemName));
while (queryRun.next())
{
vendTable = queryRun.get(tablenum(Bill_Table));
info(strfmt(“Item – %1, Name – %2”,vendTable.ItemName, vendTable.CustName));
}

}

range1range

Advertisements