Skip to main content

Posts

Showing posts with the label QueryRun

Get Product based on Item group in MSD Ax 2012

To get Item details or  Product based on Item group in Ax 2012 you can try below code in job. In this job Test_InventItemGroup is query on which you need to include inventItemgroupItem and inventTable. I have pass the range TT as item group same way you can use in your customization. Query query; QueryRun qr; QueryBuildDataSource qbds; QueryBuildRange queryBuildRange; InventItemGroupItem IntventTest,InventTest1; ; query = new Query(queryStr(Test_InventItemGroup)); qbds = query.dataSourceTable(tableNum(InventItemGroupItem)); queryBuildRange = qbds.addRange(fieldNum(InventItemGroupItem,ItemGroupId)); queryBuildRange.value("TT"); qr = new QueryRun(query); while(qr.next()) { IntventTest= qr.get(tableNum(InventItemGroupItem)); select ItemId from IntventTest1 where IntventTest1.ItemGroupId == IntventTest.ItemGroupId; info(strFmt("%1",IntventTest.ItemId)); }

How to Call query in MSD Axapta by code

To Call query in Axapta by code you can try below code. You need to create query in aot query node then pass query using querystr method in queryrun object. QueryRun queryRun; int cnt; ; queryRun = new QueryRun(queryStr(Query1)); if (queryRun.prompt()) { while (queryRun.next()) { cnt++; }

example of queryrun in MSD axapta

example of queryrun in axapta SysQueryRun queryRun = new SysQueryRun(querystr(MyQuery)); CustInvoiceJour custInvoiceJour; CustInvoiceTrans custInvoiceTrans; ; if (queryRun.prompt()) { while (queryRun.next()) { custInvoiceJour = queryRun.get(tableNum(CustInvoiceJour)); custInvoiceTrans = queryRun.get(tableNum(CustInvoiceTrans)); if (queryRun.changed(tableNum(CustInvoiceJour))) { info(strfmt("Account: %1", custInvoiceJour.invoiceAccount)); } if (queryRun.changed(tableNum(CustInvoiceTrans))) { info(strfmt("Item: %1, Qty: %2, ",custInvoiceTrans.itemId, custInvoiceTrans.qty)); } } }