Wednesday, May 20, 2015

Building query AND using query object in X++

Create and add datasource with range in X++
// Code using X++ to build the query
Query                   query;
QueryRun                queryRun;
QueryBuildDataSource    qbds;
ProjTable               ProjTable;
;

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



Use query object to retrieve AOT query
// Code using a query string
static void UseAOTQuery(Args _args)
{
    Query                           query;
    QueryRun                        queryRun;
    QueryBuildDataSource            qbds;
    QueryBuildRange                 qbr;      
    ProjTable                     projTable;   
    
    query = new query(queryStr(ProjTable));
    queryRun = new QueryRun(query);
    
    while (queryRun.next())
    {
        projTable= queryRun.get(tableNum(ProjTable));
        
        info (strFmt("%1 - %2", ProjTable.ProjId, ProjTable.Name));
    }   
}

No comments:

Post a Comment

I will appreciate your comments !

Download large bacpac (sandbox database) to DEV environment much faster

As the LCS website gets slower and slower and the database backups get bigger and bigger.  Use AZCopy to download objects out of LCS asset l...