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

Announcements

No record found.

News and Announcements icon
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 56

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!

I have the same question (0)
  • Verified answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    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
    56 on at

    Sergei,

    Sorry, i missed. let me check

  • @rp@n Profile Picture
    56 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 608

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 591 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans