How to get the EnumType used on a field in a Table

259 Views Asked by At

I want to get the Enum Type used on a field on a Table either preferably by T-SQL or by X++.

My aim is to get the Metadata of a table specifically FieldName, FieldType (If it's a string then it's length, if it's a Enum then all it's values):

I got the fieldtypes by using this code:

internal final class EnumValues
{
    public static void main(Args _args)
    {
        SqlDictionary SqlDict;

        while select fieldType from SqlDict group by SqlDict.fieldType
            where SqlDict.tabId==19503
        {
            info(strfmt("%1:%2",enum2int(SqlDict.fieldType),SqlDict.fieldType));
        }
        
    }
}

Output:

49:
8:VarString
6:UtcDateTime
4:Enum
3:Date
2:Real
1:Integer
0:String

Among the output values the only type I have to drill down now is Enum. How can I get the EnumType used on a field. If I can get that then I can get it's values from ENUMVALUETABLE and ENUMIDTABLE.

Appreciate any tips.

1

There are 1 best solutions below

0
Aliaksandr Maksimau On BEST ANSWER

The following example shows the retrieval of the enumeration ID and the enumeration name of a field that is based on an enumeration:

DictField df; 
DictEnum  de; 
enumId    id; 
df = new DictField(tablenum(CustTable), fieldnum(CustTable, AccountNum)); 
if (df) 
{ 
    id = df.enumId(); 
    if (0 != id) 
    { 
        de = new DictEnum(id); 
        if (de) 
        { 
            print de.name(); 
        } 
    } 
}

Method enumId() returns the ID of the enumeration if the field is based on an enumeration; otherwise, 0 (zero).