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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  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():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  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;
  }

Last 5 posts in Development

Leave a Reply

Your email address will not be published. Required fields are marked *