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)

How do you get a table record count in AX

(1) ShareShare
ReportReport
Posted on by 1,559

Hi Friends,

In X++, how do you get a record count in table, I don't want to use while loop.

Thanks,

River

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Select a count on the recId.  For example:

     

    AssetTable assetTable;

      

       select count(RecId) from AssetTable;

      

       info(strFmt("AssetTable has %1 records.", AssetTable.RecId));

  • Verified answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    Use Count() on RecId field on the table as suggested by Rick.

    You can also check it from your development workspace under Tools > Number of records form. It will show you total number of records not only in tables but in views, tableMaps etc. This is nice and easy way to get total count of records without writting any custom code.

  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    Ganriver, can you please mark these answers as verified? So that future forum readers can see that this is the correct answer to the question. Thanks!

  • Ganriver1 Profile Picture
    1,559 on at

    Thanks a lot, Guys.

  • Community Member Profile Picture
    on at

    Hi,

    2 question regarding the solution provided:    select count(RecId) from AssetTable;

    1. What exactly is RecId in this example? Is it an actual field name in the table, i.e. the primary key field, or is it some X++ variable?
    2. If the command is used inside a Table method, can the from tableName part be omitted?

    Thanks in advance,

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi,

    1. RecId is the actual field name, kernel field which can be found in any table. It's the unique record id.

    2. It doesn't matter where to use this statement, "from tableName" part should be in any case.

  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    In addition to Sergeis answer, the actual count of the number of records will be returned in the field of the table buffer specified in the "count()". You could use another field but usually everyone just uses the RecId field because every table has a RecId field of course. The count works on Int64, real, string fields and possibly others but I have not tested them all.

    CustTable   custTable;
    
    select count(RecId) from custTable;
    info(strFmt('custTable.RecId: %1', custTable.RecId));
    
    select count(BankCustPaymIdTable) from custTable;
    info(strFmt('custTable.BankCustPaymIdTable: %1', custTable.BankCustPaymIdTable));
    
    select count(CreditMax) from custTable;
    info(strFmt('custTable.CreditMax: %1', custTable.CreditMax));    
    
    select count(AccountNum) from custTable;
    info(strFmt('custTable.AccountNum: %1', custTable.AccountNum));

  • Community Member Profile Picture
    on at

    Thank you very much, Sergei & Anton.

    Its all clear now, and I wish I had it clarified from the online documentation as you did!

    If you can suggest a better and detailed X++/API documentation or literature (books), preferably with detailed examples as above, please do.

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