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:
Post a Comment