web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Qbds query will return the max recid based on purchid form Vend purch order jour table

(0) ShareShare
ReportReport
Posted on by

Hi all,

i write below query to return the MAX recid based on purch id from VendPurchOrderJour.

I have given From date =  7/10/2020 and to date  = 7/10/2020

Report Output

pur1.jpg

Table - VendPurchOrderJour

3733.pur2.jpg

The BOLD line should come in my report. 

In my report it's display number of lines correctly but Order date is BLANK.

The order date should be print MAX "PurchaseOrderDate" based on PURCH ID. 

code

public void excelExecution()
{
    Query                   query;
    QueryRun                qrRun;

    TransDate               maxSalesConfrmDate;
    QueryBuildDatasource    qbds,qbds1;
    QueryBuildRange         qbr;

    RecId                   chkRecid;
    boolean                 headerPrint = true;

    i = 1;

    // initlize the SysExcelApplication instance
    sysExcelApplication  = SysExcelApplication::construct();

    //create excel workbook and excel worksheet
    excelWorkbookCollection  = sysExcelApplication.workbooks();
    excelWorkbook    = excelWorkbookCollection.add();
    excelWorksheetCollection = excelWorkbook.worksheets();
    excelWorksheet = excelWorksheetCollection.itemFromNum(1);

    // query ( GDJ_VendVendGroupQR )started ***

    query = new Query(queryRun.query());

    qbds = query.dataSourceNo(1).addDataSource(tablenum(VendPurchOrderJour));
    qbds.relations(true);

    // date range
    qbr = qbds.addRange(fieldNum(VendPurchOrderJour,PurchOrderDate));
    qbr.value(queryRange(fromDate, toDate));

    qbds.addGroupByField(fieldNum(VendPurchOrderJour, PurchId));
       
    qbds.addSelectionField(fieldNum(VendPurchOrderJour, RecId), SelectionField::Max);

    qbr = qbds.addRange(fieldNum(VendPurchOrderJour, PurchId));
    qbr.value("");

    qrRun = new QueryRun(query);

    try
    {
        while (qrRun.next())
        {
            vendPurchOrderJour = qrRun.get(TableNum(VendPurchOrderJour));
        }
    }
}

Kindly let me know what change is required in my above query?

please give me more shed on this.

thanks!

  • Verified answer
    Sergei Minozhenko Profile Picture
    on at
    RE: Qbds query will return the max recid based on purchid form Vend purch order jour table

    Hi @pr@n,

    You have an only selection field by VendPurchOrderJour.RecId, but not by PurchOrderDate. Is it done intentionally?

    Also, you need to specify OrderMode = OrderMode::GroupBy for QueryBuildDataSource object.

  • @rp@n Profile Picture
    on at
    RE: Qbds query will return the max recid based on purchid form Vend purch order jour table

    Sergei,

    Sorry, i missed. let me check

  • @rp@n Profile Picture
    on at
    RE: Qbds query will return the max recid based on purchid form Vend purch order jour table

    thanks a lot Sergei, its working

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans