Monday 6 January 2014

Dynamic query in ax 2012


static void queryRunRentalCarListAOT(Args _args)
{
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
CarTable carTable;
RentalTable rentalTable;
;
query = new Query(querystr(RentalCarList));
queryBuildDataSource = query.dataSourceTable(tablenum(CarTable));
queryBuildRange = queryBuildDataSource.findRange(fieldnum(CarTable, ModelYear));
queryBuildRange.value("2008..");
queryRun = new QueryRun(query);
while (queryRun.next())
{
carTable = queryRun.get(tablenum(CarTable));
rentalTable = queryRun.get(tablenum(RentalTable));
info (strfmt("CarId %1, RentalId %2", carTable.CarId, rentalTable.RentalId));
}
}


static void queryRunRentalCarList(Args _args)
{
Query query;
QueryBuildDataSource queryBuildDataSource1,
queryBuildDataSource2;
QueryBuildRange queryBuildRange;
QueryBuildLink queryBuildLink;
QueryRun queryRun;
CarTable carTable;
RentalTable rentalTable;
;
query = new Query();
queryBuildDataSource1 = query.addDataSource(tablenum(CarTable));
queryBuildRange = queryBuildDataSource1.addRange(fieldnum(CarTable, ModelYear));
queryBuildRange.value("2008..");
// Add the second datasource to the first data source
queryBuildDataSource2 = queryBuildDataSource1.addDataSource(tablenum(RentalTable));
queryBuildLink = queryBuildDataSource2.addLink(fieldnum(CarTable,CarId),fieldnum(RentalTable, CarId));
queryRun = new QueryRun(query);
// Loop through all the records returned by the query
while (queryRun.next())
{
carTable = queryRun.get(tablenum(CarTable));
rentalTable = queryRun.get(tablenum(RentalTable));
info (strfmt("CarId %1, RentalId %2", carTable.CarId,
rentalTable.RentalId));
}
}

No comments:

Post a Comment

SQL/SSRS Interview questions I thought of blogging some SQL/SSRS interview questions.

Below are some. I will add more, when I complete the compilation 1. What is OLTP(Online Transaction Processing)? OLTP stands ...