Saturday, 21 December 2013

Building a query object in ax 2012

static void ProjTableQuery(Args _args)
{
Query query;
QueryBuildDataSource qbds1;
QueryBuildDataSource qbds2;
QueryBuildRange qbr1;
QueryBuildRange qbr2;
QueryRun queryRun;
ProjTable projTable;
query = new Query();
qbds1 = query.addDataSource(tableNum(ProjTable));
qbds1.addSortField(
fieldNum(ProjTable, Name),
SortOrder::Ascending);
qbr1 = qbds1.addRange(fieldNum(ProjTable,Type));
qbr1.value(queryValue(ProjType::FixedPrice));
qbr2 = qbds1.addRange(fieldNum(ProjTable,ProjId));
qbr2.value(queryValue('2') + '*');
qbds2 = qbds1.addDataSource(tableNum(ProjEmplTrans));
qbds2.relations(true);
qbds2.joinMode(JoinMode::ExistsJoin);
queryRun = new QueryRun(query);
while (queryRun.next())
{
projTable = queryRun.get(tableNum(ProjTable));
info(strFmt(
"%1, %2, %3",
projTable.ProjId,
projTable.Name,
projTable.Type));
}

             }

No comments:

Post a Comment