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 :
Microsoft Dynamics AX (Archived)

Limit number of returned records in Query

(0) ShareShare
ReportReport
Posted on by 935

Hi Guys,

I'm working to get the last 3 customer transactions in AX 2012. I have a query that I used in a view to display the records. The records being fetched is either open or invoiced sales line order. There where no other criteria set in the query. I can display the last 3 records - which i have a class and select the records using a while statement in the class. Though I can output the correct records, I am concern with the optimization when the view is used in the class (for processing). Cause for sure, the view will contain all the customer transaction, and I'm considering the amount of time it requires to process just to get the last 3 records. 

In SQL, a TOP 3 keyword can be used to fetch the 3 records. I am not sure if there is an equivalent way of doing this in AX. FirstOnly can only be used in select statement and not in a while select.

Any thoughts please.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    firstOnly technically can be used in while select, it's just not very useful, but you can use firstOnly10 to return only 10 records. Unfortunately X++ doesn't support TOP statement in a more flexible way.

    Always consult Select Statement Syntax if in doubt about what can and cannot be used.

  • Suggested answer
    danfreitas Profile Picture
    5 on at

    I believe you can do a simple select using firstOnly10 like Martin suggested and then iterate over the result using the next keyword. Something like this I think:

    while (table)

    {

     do something to table

     next table;

    }

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans