How to get all Field Names,edt used,label,datatype and size of datatype used in a InventTable in Ax7/Ax 2012?

I need to get all field names,label,edt used,datatype and size of datatype for any table/view? is it possible to display the relations attached in a table too!! please reply with the code/job.

Thank you

You can use SysDictTable and SysDictField classes to get that information. Look at the cross references for examples in standard code.

Example - \Data Dictionary\Tables\WHSTmpFieldName\Methods\populateFieldNames

Can we get Relations defined for the table using SysDicTable and SysDictField Classes

Yes, you can use SysDictTable.relations().

Yes, \Classes\SysDictTable\relations

I am getting fieldnames,datatypes,label and string length but relations are not coming. I am new to this . please suggest

That method return a Set and you may need to iterate through the elements in it.

Look at \Classes\DMFEntityBase\getRelationStr

Only first relation defined in the tble is coming… how to iterate through the elements. can you have any sample code related to the above image .pls suggest

use this way u will get relations.

thanks for the code but my requirement is display of fieldnames,label,datatype,strlength and relations for the table. As MArtin Said using Sysdicttable.relations is fetching the relations but only first relation is printing. i need to iterate through the table to print relations. pls suggest

Please show us the code that you use to iterate the set returned by relations(). We can’t spot bugs in code that we’ve never seen.

static void printRelations(Args _args)
{
    SysDictTable    dictTable = new SysDictTable(tableNum(Accountant_BR));
    SysDictRelation sysDictRelation;
    int             cnt;
    int             i;
    int             line;
     
    sysDictRelation = new SysDictRelation(dictTable.id());
    
    cnt = dictTable.relationCnt();
    
    for (i=1; i<=cnt; i++)
    {
        sysDictRelation = new SysDictRelation(dictTable.id());
        info(dictTable.relation(i));
        if (sysDictRelation.loadNameRelation(dictTable.relation(i)))
        {
            for (line = 1; line<=sysDictRelation.lines(); line++)
            {
               info(sysDictRelation.lineDescription(line));
            }
        }
    }
   
}

You may also use this sample code to get the relations.

public class RESModule_Test 
{        
    public static void main(Args _args)
    {
        Dictionary dict = new Dictionary();
        DictTable     dictTable = new SysDictTable(Tablenum(DirPartyTable));
        //DictRelation  dictRelation = new SysDictRelation(dict.tableName2Id("ResProperty"));
        FieldID       fieldId   = dictTable.fieldnext(0);
        //        TableId       tableId   = dicttable.tableType();
        DictField     dictField;

        while(fieldId)
        {
            dictField = dictTable.fieldObject(fieldId);
            info(strfmt("%1,%2,%3,%4",dictField.name(),dictField.baseType(),dictField.label(),dictField.stringLen()));
            fieldId   = dictTable.fieldNext(fieldId);
            
        }
        info(strfmt("%1",dicttable.relation(true)));
    }

}

Hi Martin, This is the code i am using .

Thank You Very much Kranthi… You made my day… It’s Working. As I am new to this,your help is very much appreciable Thank you. And special thanks to Martin I always get inspired from your answers in various blogs and communities.

Kranthi’s code uses an alternative approach, this is how the same logic would looked like with relations() method discussed above:

Set relations = new SysDictTable(tableNum(Accountant_BR)).relations();
SetEnumerator enumerator = relations.getEnumerator();
SysDictRelation relation;
int line;

while (enumerator.moveNext())
{
    relation = enumerator.current();
    info(relation.name());

    for (line = 1; line <= relation.lines(); line++)
    {
        info(relation.lineDescription(line));
    }
}

It can be even shorter in AX 7:

Set relations = new SysDictTable(tableNum(Accountant_BR)).relations();
SetEnumerator enumerator = relations.getEnumerator();

while (enumerator.moveNext())
{
    SysDictRelation relation = enumerator.current();
    info(relation.name());

    for (int line = 1; line <= relation.lines(); line++)
    {
        info(relation.lineDescription(line));
    }
}

Thanks Martin. I even want the code in Ax7 . My requirement is giving a module in ax to ax CRM team which includes the tables information should be exported.

I tried the same logic for showing indexes . index name is coming but the field used in the index is not fetching , which method to use in for loop? see the below code

static void Indexes(Args _args)
{
Set indexes = new SysDictTable(tableNum(Accountant_BR)).indexes();
SetEnumerator enumerator = indexes.getEnumerator();
SysDictIndex idx;
int line;

while (enumerator.moveNext())
{
   
    idx  = enumerator.current();
    info(idx.name());
    for (line = 1; line <= idx.numberOfFields(); line++)
    {
        //info(idx.field(line));
    }

}

}

Unfortunately you didn’t explain your problem, but I see you’re trying to put the return value of field() to info(). field() returns the field ID, so you would have to convert it to string first. But you likely want a field name, not ID, and you code is missing the conversion from ID to name.

Try this instead and notice the use of dictTable.fieldName():

SysDictTable dictTable = new SysDictTable(tableNum(Accountant_BR));
SetEnumerator indexEnumerator = dictTable.indexes().getEnumerator();

while (indexEnumerator.moveNext())
{
    SysDictIndex dictIndex = indexEnumerator.current();
    info(dictIndex.name());
    for (int fieldIdx  = 1; fieldIdx <= dictIndex.numberOfFields(); fieldIdx++)
    {
        info(dictTable.fieldName(dictIndex.field(fieldIdx)));
    }
}

As i am new to this, don’t know which method to pass so i tried ur relations() code for indexes() above which went wrong. Thanks again for your reply. By using above code I had fetched FieldGroups and Columns in the FieldGroups as well.

How to fetch EDT/Enum used for the fields in the table? see the below one

        DictTable     dictTable = new SysDictTable(Tablenum(Accountant_BR));
        FieldID       fieldId   = dictTable.fieldnext(0);
        DictField     dictField;

    
        while(fieldId)
        {
            dictField = dictTable.fieldObject(fieldId);
            info(strfmt("%1,%2,%3,%4",dictField.name(),dictField.baseType(),dictField.stringLen(),dictField.label()));
            fieldId   = dictTable.fieldNext(fieldId);
            
        }