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

Add Prompt window to form for grid filtering Method 2 in Ax 2009

public class FormRun extends ObjectRun

{
Bill_Table bt;
QueryRun queryRun;
QueryBuildDataSource qbd;
Bill_Table vendTable;
QueryBuildRange range,range1;
int ct, i;
Str ss,ss1;
}

Datasource Init
public void init()
{
// Query query = new Query();
super();
range =this.query().dataSourceNo(1).addRange(fieldnum(Bill_Table,ItemName));
range1 =this.query().dataSourceNo(1).addRange(fieldnum(Bill_Table,CustName));
queryRun = new QueryRun(this.query());
queryRun.prompt(); // To Prompt the dialog
ct = queryRun.query().dataSourceTable(tablenum(Bill_Table)).rangeCount();
range = queryRun.query().dataSourceTable(tablenum(Bill_Table)).range(1);
range1 = queryRun.query().dataSourceTable(tablenum(Bill_Table)).range(2);
// info(strfmt(“Range Field %1, Value %2, Value %3 “,range.AOTname(),range.value(),range1.value()));
ss=range.value();
ss1=range1.value();
}

Form Run
public void run()
{
super();
Bill_Table_ds.filter(fieldnum(Bill_Table,ItemName),ss);
Bill_Table_ds.filter(fieldnum(Bill_Table,CustName),ss1);
}

OUTPUT

prompt b4after