web
You’re offline. This is a read only version of the page.
close
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 30

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!

 

}

I have the same question (0)
  • Verified answer
    udaY-ch Profile Picture
    5,133 on at

    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

  • @rp@n Profile Picture
    30 on at

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

  • @rp@n Profile Picture
    30 on at

    it's done

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans