A blog offering various X++ code snippets and tips for Microsoft Dynamics AX

Friday, January 09, 2009

Getting the number of records from table name.

I replied to the following question on the forums:

How to check if a table has records in it, from its name, NOT from a buffer.

The trick is some standard AX dict classes reflection (specifically DictTable):


static void recordsExist(Args _args)
{
  SysDictTable dictTable;
  ;
  dictTable = new SysDictTable(tableName2Id('TableStringHere'));

  if (dictTable)
  {
    if (dictTable.recordCount() > 0)
      info ("This table has records.");
    else
      info ("No records");
  }
  else
    info ("Table does not exist");
}


If you any questions or comments e-mail me on: mirko@mirkobonello.com