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

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

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    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.

  • Satch Profile Picture
    10 on at

    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

  • Sergei Minozhenko Profile Picture
    23,093 on at

    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

    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++ :)

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

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

    SysDictTable::CASRecordcount(UtilIdElements.name);

  • Satch Profile Picture
    10 on at

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

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    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.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    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;

  • Suggested answer
    Satch Profile Picture
    10 on at

    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);
                }
            }
    }

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 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans