Dec 2, 2013

QueryRangeFilter in AX

static void QueryRangeFilter(Args _args)
{
Query query;
QueryBuildDataSource datasource;
QueryBuildRange range;
QueryFilter filter;
QueryRun queryRun;
int countAfterChange = 0, countBeforeChange = 0;

query = new Query();
datasource = query.addDataSource(tableNum(CustTable));
datasource = datasource.addDataSource(tableNum(SalesTable));
datasource.joinMode(JoinMode::InnerJoin);
datasource.relations(true);

datasource.addLink(fieldNum(CustTable, AccountNum),
fieldNum(SalesTable, CustAccount));

filter = query.addQueryFilter(datasource,
fieldStr(SalesTable, CurrencyCode));

filter.value(SysQuery::value('USD'));

//range = datasource.addRange(fieldNum(SalesTable, CurrencyCode));
//range.value(SysQuery::value('EUR'));

queryRun = new QueryRun(query);
while (queryRun.next())
{
countBeforeChange ++;
if (queryRun.changed(tableNum(CustTable)))
countAfterChange ++;
}

info(strFmt("CountAfterChange : %1", countAfterChange ));
info(strFmt("CountBeforeChange : %1", countBeforeChange ));
}

1 comment:

Anonymous said...

Thanks for the helpful post ... Keep posting