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

wants to return latest confirmdocnum form custinvoicejour with qbds query in ax 2012 r3

(0) ShareShare
ReportReport
Posted on by 6

hi all,

Dialog -- 

qr5.jpg

table - Cust Confirm Jour

qur2.jpg

my query --

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


    QueryBuildDatasource qbds;
    QueryBuildRange        qbr;

    RecId chkRecid;

    query = queryRun.query();

    qbds = query.addDataSource(tablenum(CustConfirmJour));


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

   queryRun = new QueryRun(query);

    while (queryRun.next())
    {
           custConfirmJour = queryRun.get(TableNum(CustConfirmJour));

            chkRecid = custConfirmJour.RecId;
            info(strFmt("%1",chkRecid));

     }

i wants to return the latest confirmation doc num. means in the excel screen shot the BOLD marked recid should only return

Kindly let me know what line of code is required to add?

please give me more shed on this.

thanks!

 

}

  • @rp@n Profile Picture
    6 on at
    RE: wants to return latest confirmdocnum form custinvoicejour with qbds query in ax 2012 r3

    it's done

  • @rp@n Profile Picture
    6 on at
    RE: wants to return latest confirmdocnum form custinvoicejour with qbds query in ax 2012 r3

    why you removed date filter from query? it should be rite  ?

  • Verified answer
    udaY-ch Profile Picture
    4,624 on at
    RE: wants to return latest confirmdocnum form custinvoicejour with qbds query in ax 2012 r3

    Hi,

    Try this code, if you haven't found already.

    public static void queryGroup(Args _args)
    {
        Query                   query;
        QueryRun                qr;
        QueryBuildRange         qbr;
        QueryBuildDatasource    qbds;       
        CustConfirmJour         custConfirmJour;   
        
        query = new Query();
        qbds = query.addDataSource(tablenum(CustConfirmJour));
        
        //You should have these two lines to group the salesId and get the last reference.
        qbds.addGroupByField(fieldNum(CustConfirmJour, SalesId));
        qbds.addSelectionField(fieldNum(CustConfirmJour, RecId), SelectionField::Max);
        
        qbr = qbds.addRange(fieldNum(CustConfirmJour, SalesId));
        qbr.value("");
    
        qr = new QueryRun(query);
    
        while (qr.next())
        {
            custConfirmJour = qr.get(TableNum(CustConfirmJour));         
            info(strFmt("%1", custConfirmJour.RecId));
        }
    }

    Uday

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,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,983 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans