Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Code to get the #of records in september2020 in all tables

(0) ShareShare
ReportReport
Posted on by 10

Hi,

I have calculated that in September-2020 25.000.000 records are used.

To solve this I need to know which tables use so much records in 1 month

Does anybody have a piece of code like:

While walk trough every table inAOT

{

if(table.createdDate)

{

Select count of (recid) from table, where createdDate >= 01\09\2020 && createdDate <= 30\09\2020

Info(tablename, table.recid)

}

}

I'm working with some older version of Axapta, but maybe soemone knows the code and I can use it on that version

  • Suggested answer
    Satch Profile Picture
    10 on at
    RE: Code to get the #of records in september2020 in all tables

    Thanks. This and with some other code I have found, I could fix it:

    static void CountRecsMonth(Args _args)
    {
       UtilElements     _UtilElements;
       SysDictTable     SysDictTab;
       NumberOf         TotalField;
       tableId          tabel;
    
       Common           common;
       DictTable        dictTable;
       int              x;
    
        ;
        while select _utilelements order by name
            where _utilelements.recordType == utilElementType::Table
            {
            if(tableName2id(_utilelements.name) != 0 && tableName2id(_utilelements.name) != tabel)
                {
                SysDictTab = SysDictTable::newTableId(tableName2Id(_utilElements.name));
                TotalField = SysDictTab.fieldCnt();
                if (TotalField)
                    {
                    dictTable = new DictTable(tableName2id(_utilelements.name));
                    common = dictTable.makeRecord();
    
                    common.selectForUpdate(false);
    
                    select count(RecId) from common
                        where common.(fieldName2id(dictTable.id(), 'CreatedDate')) >= 01\09\2020
                        && common.(fieldName2id(dictTable.id(), 'CreatedDate')) <= 30\09\2020;
    
                    info(strfmt("%1;%2",_utilelements.name,common.RecId));
                    }
                tabel = tableName2id(_utilelements.name);
                }
            }
    }

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Code to get the #of records in september2020 in all tables

    Hi Satch,

    Here are some references on how to use UtilElements

    stackoverflow.com/.../how-do-i-query-the-objects-utilelements-and-utilidelements-to-fetch-correct-resu

    How to select data if you have only TableId

    www.doens.be/.../

    You just need to add check if CreatedDateTime is activated for table

    In the end, you should get something like this

    select count(RecId) from common
        where common.(fieldName2id(dictTable.id(), 'CreatedDateTime')) <= toDate
           && common.(fieldName2id(dictTable.id(), 'CreatedDateTime')) >= fromDate;

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Code to get the #of records in september2020 in all tables

    That's the issue. I was trying to check if we could use "Common". But, by default common does not table CreatedDateTime object.

    Unless and until you query by individual tables, I don't see how you could use createdDateTime.

  • Satch Profile Picture
    10 on at
    RE: Code to get the #of records in september2020 in all tables

    But how to implement  'select where createddate >= ....'?

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Code to get the #of records in september2020 in all tables

    You can use SysDictTable class. To find total number of records, you can use

    SysDictTable::CASRecordcount(UtilIdElements.name);

  • Satch Profile Picture
    10 on at
    RE: Code to get the #of records in september2020 in all tables

    Hi, thanks. We're using Oracle.

    And thats a "black box" for me.

    I can do all kind of selects in X++, and am pretty used to that. (Except the Utilelements stuff)

    So pretty please in X++ :)

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Code to get the #of records in september2020 in all tables

    Hi Satch,

    I recommend not to use x++ to get this information, but use SQL server features instead.

    You can start with top biggest tables by rows or by size and narrow down list of tables for analysis.

    stackoverflow.com/.../7892349

  • Satch Profile Picture
    10 on at
    RE: Code to get the #of records in september2020 in all tables

    Hi, thanks.

    You're right. This is only valid for tables with created date. There's no other option it seems.

    But "translating" Utildelements to Table is some grey area for me...:(

    How to translate it so that I can do: Select from 'Table'

    Where 'Table' is the table from utilElements

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Code to get the #of records in september2020 in all tables

    Hi Satch,

    Not sure if it will be possible to get this count as all tables don't have CreatedDateTime property enabled.

    To loop through all the tables you can use UtilIdElements and filter on the basis of field RecordType value UtilElementType::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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,208 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,970 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans