With the following job we can create and execute the query :
Static void Querytest(Args _Args)
{
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildDataSource queryBuildDataSource1;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
CustTable custTable;
DirPartyTable DirPartyTable;
;
query=new query(); //Initialize Query
queryBuildDataSource=query.addDataSource(tableNum(CustTable)); //Add Query
queryBuildDataSource.addSortField(fieldNum(custTable,AccountNum),SortOrder::Descending); //Add sorting
queryBuildRange=queryBuildDataSource.addRange(fieldNum(CustTable,AccountNum)); // Add Range
queryBuildRange.value(queryValue('11')+('*')); // Add Query Value
queryBuildRange=queryBuildDataSource.addRange(FieldNum(CustTable,AccountNum));
queryBuildRange.value(queryValue('22')+('*'));
//queryBuildDataSource1=queryBuildDataSource.addDataSource(tableNum(CustTrans)); //Add other Data Source for Joining
//queryBuildDataSource1.relations(true);// Enable Relation
// queryBuildDataSource1.joinMode(JoinMode::InnerJoin);//Define Join Mode
queryRun= new QueryRun(query); //Pass query to run it
while(queryRun.next())
{
custTable=queryRun.get(tableNum(CustTable));
print(strFmt("Customer Name, Account num and Currency are %1 , %2 and %3",DirPartyTable::findRec(CustTable.Party).Name,CustTable.AccountNum,CustTable.Currency));
pause;
}
}
Happy AX coding!!!!!
Static void Querytest(Args _Args)
{
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildDataSource queryBuildDataSource1;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
CustTable custTable;
DirPartyTable DirPartyTable;
;
query=new query(); //Initialize Query
queryBuildDataSource=query.addDataSource(tableNum(CustTable)); //Add Query
queryBuildDataSource.addSortField(fieldNum(custTable,AccountNum),SortOrder::Descending); //Add sorting
queryBuildRange=queryBuildDataSource.addRange(fieldNum(CustTable,AccountNum)); // Add Range
queryBuildRange.value(queryValue('11')+('*')); // Add Query Value
queryBuildRange=queryBuildDataSource.addRange(FieldNum(CustTable,AccountNum));
queryBuildRange.value(queryValue('22')+('*'));
//queryBuildDataSource1=queryBuildDataSource.addDataSource(tableNum(CustTrans)); //Add other Data Source for Joining
//queryBuildDataSource1.relations(true);// Enable Relation
// queryBuildDataSource1.joinMode(JoinMode::InnerJoin);//Define Join Mode
queryRun= new QueryRun(query); //Pass query to run it
while(queryRun.next())
{
custTable=queryRun.get(tableNum(CustTable));
print(strFmt("Customer Name, Account num and Currency are %1 , %2 and %3",DirPartyTable::findRec(CustTable.Party).Name,CustTable.AccountNum,CustTable.Currency));
pause;
}
}
Happy AX coding!!!!!
Hi,
ReplyDeleteyou can use the expression
SysQuery::valueLikeAfter('11')
instead of queryValue('11')+('*'),
i think its a better approach.
regards,
Mathias
Pidr
ReplyDeletesee dynamics 101 site
ReplyDeleteBut why and where do we use these queries?? Any real time example / scenario?
ReplyDeleteBut why and where do we use these queries?? Any real time example / scenario?
ReplyDeleteThank You and that i have a dandy offer: condo kitchen renovation
ReplyDelete