Get enum label value by Table field id

 I have a table record with several fields. I’m reading the fields of this table but I don’t know the type of any of them. Some might be of type string, others of type numeric, and still others of type enum.

Not knowing the type of enum Ax only returns the numeric value, but I want the label.

This code gets the enum label value by passing the table fieldId and its value

public str tableEnumFieldValue2Str()
    { 
        str _fieldValueStr;
        TableId tableId = tableNum(MyTable);
        FieldId fieldId = fieldNum(MyTable, MyEnumField);
        
        //Checkif field is an enum type. If it's so then show label value instead of value
        SysDictField field = new SysDictField(tableId , fieldId);
        EnumId   enumId        = field.enumId();
        str ret = _fieldValueStr;

        if(enumId != 0)
        {
            //Enum!
            DictEnum dictEnum  = new DictEnum(enumId);
            int      EnumValue = str2Int(_fieldValueStr);

            ret = dictEnum.index2Label(EnumValue);
        }

        return ret;
    }

Comments