Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

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

Posted on by 5,901

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
    @rp@n 5,901 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
    @rp@n 5,901 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
    Sergei Minozhenko 23,089 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans