Tuesday, 11 April 2017

Date Range filter in x++ query

static void QueryDateRange(Args _args)
{
    Query                   query;
    QueryRun                queryrun;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr;
    PurchLine               purchLine;
    TransDate               fromDate, Todate;
    ;
   
    fromDate = mkDate(19,11,2016);
    Todate   = mkDate(20,12,2016);
   
    query = new Query();
   
    qbds = query.addDataSource(tableNum(PurchLine));
   
    qbds.addSortField(fieldNum(PurchTable, PurchId), SortOrder::Ascending);
   
    qbr     = qbds.addRange(fieldNum(PurchLine, deliveryDate));
   
    qbr.value(queryRange(fromDate, Todate));
   
    queryrun = new QueryRun(query);
   
    while(queryrun.next())
    {
        purchLine = queryrun.get(tableNum(purchLine));
       
        info(strFmt("%1", purchLine.PurchId));
    }
}

No comments:

Post a Comment