Thursday, December 18, 2008

Browse the data dictionary with X++

Browsing the Data dictionary through X++ code is easier than you may think. Let’s say you want to list all of the fields in table InventTable.
This is one way to do it:

  static void FO_dataDictionary(Args _args)
  {
      Dictionary      dictionary = new Dictionary();
      DictTable       table;
      DictField       field;
      InventTable     inventTable;
      int             j;
      ;
 
      table = dictionary.tableObject(inventTable.TableId);
 
      print table.id();
      print table.name();
      pause;
 
      for(j=1; j <= table.fieldCnt(); j++)
      {
          field = new DictField(table.id(), 
                                table.fieldCnt2Id(j));
          print field.name();
      }
 
      pause;
  }

Using this job we list all of the fields in InventTable, even the system fields such as dataAreaId and createdDate. If we want to exclude the system fields we add an If – statement that checks if the fields are system fields using the method isSystem():
 static void FO_dataDictionary(Args _args)
  {
      Dictionary      dictionary = new Dictionary();
      DictTable       table;
      DictField       field;
      InventTable     inventTable;
      int             j;
      ;
 
      table = dictionary.tableObject(inventTable.TableId);
 
      print table.id();
      print table.name();
      pause;
 
      for(j=1; j <= table.fieldCnt(); j++)
      {
          field = new DictField(table.id(), 
                                table.fieldCnt2Id(j));
 
          if(!field.isSystem())
          {
              print field.name();
          }
 
      }
 
      pause;
  }



No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...