Friday, April 22, 2016

Dynamic Query to pass Range b/w two Dates in ax 2012

static void DateRange2(Args _args)
{
    date            dateFrom    = 01\01\2012 ;
    date            dateTo      = 31\01\2012 ;
    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));
    }

}

1 comment:

  1. Messenger İndir
    Messenger, Facebook messenger indir ile birlikte çalışan ve isterseniz Facebook’a girmeden messenger yükle mesaj yollayabileceğiniz uygulamadır.

    ReplyDelete

Export a copy of the standard user acceptance testing (UAT) database

 Reference link: Export a copy of the standard user acceptance testing (UAT) database - Finance & Operations | Dynamics 365 | Microsoft ...