How to write Dynamic query in x++

 public static void main(Args _args)

{


Query q;


QueryRun qr;


QueryBuildDataSource qbds;


QueryBuildRange qbr;


q = new Query();


Sports sports; //tablename tablename reference


qbds=q.addDataSource(tableNum(Sports)); //addDataSource is used to add the table


qbds.addSortField(fieldNum(Sports,RunRate),SortOrder::Descending); // addSortField is used to sort the fields in asc or desc


qbr=qbds.addRange(fieldNum(Sports, RunRate)); //Addrange method is used to filter the records based on range


qbr.value(SysQuery::range('100','200'));


qr=new QueryRun(q);  //Pass query to run it


while (qr.next())

{


sports=qr.get(tableNum(Sports));


info(strfmt("%1 - %2",Sports.Team,Sports.RunRate));

}


}

Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O