web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Tables in a container

(0) ShareShare
ReportReport
Posted on by 700
I have a question about containers: can I use a container in order to loop over tables?
I need to loop over 6 tables, in each table I want to loop over records to modify them
Is it possible to loop over tables using a container? I was going for something like this:

container myCon = ['table1','table2','table3','table4','table5','table6' ];
  ;
  for(i = 1; i<=6, i++)
  {
         while select count (RecID) from conPeek(myCon, i)
         {
                  do smth
         }
   }

In place of "from conPeek(myCon, i)" the query requires the table name. I would like to place there the tablename from the container. Does anybody have an idea for this?

Thank you all

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Annette Theissen Profile Picture
    1,653 on at

    Hi,

    the following will do what you need ...

       container   tableIDs = [tableNum(InventTable), tableNum(CustTable)];
       int         i;
    
       void doSomething(TableId _tableId)
       {
           DictTable   dictTable;
           Common      common;
    
           DictTable   = new DictTable(_tableId);
           Common      = dictTable.makeRecord();
    
           select count(RecId) from common;
    
           info(strFmt("%1:%2", DictTable.name(), Common.RecId));
       }
    
       for (i = 1; i <= conLen(tableIDs); i++)
       {
            doSomething(conPeek(tableIDs, i));
       }


    Hope this helps!

    Kind regards,

    Annette

  • Suggested answer
    Ivan (Vanya) Kashperuk Profile Picture
    Microsoft Employee on at

    static void Job4(Args _args)

    {

       SysDictTable dt = SysDictTable::newName('InventTable');

       Common cm = dt.makeRecord();

       while select cm

       {

           info(strFmt('%1', cm.getFieldValue('ItemId')));

       }

    }

  • OrangeRocks Profile Picture
    700 on at

    Hallo Ivan,

    thanks for your reply.

    However I am looking for something that will loop through a few tables  - I guess I would want to set a number in the function newName rather than the table name like 

    newName('InventTable').


    I also noticed that it is possible to get only this function :

    SysDictTable::newTableId

     and not

    SysDictTable::newName('InventTable');


  • Ivan (Vanya) Kashperuk Profile Picture
    Microsoft Employee on at

    this is just a string - you can pass in a variable or anything else in there.

    Or, rather, answering the second part - you seem to be on an earlier version of AX, where the newName() method does not exist yet. newTableId() is just as good. Only instead of the table name, you need to pass in the ID of the table.

    You can get it based on the name through tablename2id() function, if necessary

    Also take a look at the example Annette provided, where she uses new DictTable() instead - the end result is the same, just a preference, I guess, of not using the new constructor directly

  • Annette Theissen Profile Picture
    1,653 on at

    Oh, didn't mean to say anything by using new DictTable() ... old habits, I guess, though that's not an excuse I myself would accept :-S

    So: Of course it's cleaner code to use SysDictTable!

    (My point was more about how to get from the container full of tableIDs to counting the records in each of the tables; that's what I thought the original question was about)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans