Monday, 11 April 2016

Static Query with Query Build Range

We can add a range for AOT static query like follow


static void Job52(Args _args)

{

    date            dateFrom    = 31\3\2008 ;

    date            dateTo      = 31\01\2010 ;

    CustInvoiceJour custInvoiceJour;

    Query           query = new Query(queryStr (CustInvoiceJour)); // Query name.

    QueryRun        qr;

    QueryBuildRange qbr;

    ;



    // Find the InvoiceDate range on AOT Query.

    qbr = query.dataSourceTable( tablenum (CustInvoiceJour))

            .findRange( fieldNum (CustInvoiceJour, InvoiceDate));



    // We can check if the query range does exist, if not, we can create it.

    if (!qbr)

    {

        qbr = query.dataSourceTable( tableNum (CustInvoiceJour))

            .addRange( fieldNum (CustInvoiceJour, InvoiceDate));

    }



    // Assigning query range value.

    qbr.value(SysQuery::range(dateFrom, dateTo));



    // We can also define an Order By through code.

   query.dataSourceTable( tableNum (CustInvoiceJour))

        .addOrderByField( fieldNum (CustInvoiceJour, OrderAccount));



    // Executing our query.

    qr = new QueryRun(query);



    // Looping through query results.

    while (qr.next())

    {

        // Assinging query results to table buffer.

        custInvoiceJour = qr.getNo( 1 );



        // Showing results.

        info( strFmt ('%1 - %2 - %3' , custInvoiceJour.InvoiceDate,

                                    custInvoiceJour.SalesId,

                                    custInvoiceJour.OrderAccount));

    }

}
gyus if any shortest way apart from this ?

No comments:

Post a Comment