Skip to main content

Notifications

Announcements

No record found.

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 6

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!

  • @rp@n Profile Picture
    6 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

  • @rp@n Profile Picture
    6 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

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,091 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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans