Wednesday, February 18, 2015

How to find the nth record using the query(qr.addPageRange(postion,postion))

Hi All,

Below is the example of how to find the nth record position using query

static void nthrecordPos(Args _args)
{  
    Query                   q;
    QueryBuildDataSource    qbds;
    QueryRun                qr;
    PurchTable              purchTable;
   
    q = new Query();
    qbds= q.addDataSource(tableNum(PurchTable));
    qbds.addOrderByField(fieldNum(PurchTable, PurchId));
   
    qr = new QueryRun(q);
    qr.literals(true);
    qr.enablePositionPaging(true);
    qr.addPageRange(10,12);
   
    while ( qr.next() )
    {
        purchTable = qr.get(tablenum(PurchTable));
        info(strfmt("%1", purchTable.RecId));
    }
}

Let say in the purchTable having 100 records, wanted to find the 10 to12 th record, by using the "qr.addPageRange(10,12)", it fetches on the 10th, 11th and 12th records.