Tuesday, 24 July 2018

Query in AX 2012

Runtime query in AX 2012


// Code using X++ to build the query
Query                   query;
QueryRun                queryRun;
QueryBuildDataSource    qbds;
SalesTable              salesTable;
;

query    = new Query();
// Add a datasource to the query
qbds     = query.addDataSource(tableNum(SalesTable));
// Add a range to the newly added datasource.
qbds.addRange(fieldNum(SalesTable,SalesId)).value("00403_1036..00412_1036");
 
queryRun = new QueryRun(query);
 
while(queryRun.next())
{
   salesTable  =   queryRun.get(tableNum(SalesTable));
   info(SalesTable.SalesId + ", " + SalesTable.CustAccount);
}


// Code using a query string
static void Job14(Args _args)
{
    Query                           query;
    QueryRun                        queryRun;
    QueryBuildDataSource            qbds;
    QueryBuildRange                 qbr;   
    EcoResDistinctProductVariant    ecoResDistinctProductVariant; 
 
    query = new query(queryStr(EcoResProductVariantsPerCompany));
    queryRun = new QueryRun(query);
 
    while (queryRun.next())
    {
        ecoResDistinctProductVariant = queryRun.get(tableNum(ecoResDistinctProductVariant));
     
        info (strFmt("%1 - %2", EcoResDistinctProductVariant.SearchName, EcoResDistinctProductVariant.ProductMaster));
    } 
}


http://kashperuk.blogspot.com/2011/10/tutorial-ax2012-new-way-of-accessing.html

No comments:

Post a Comment

Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...