Friday, January 29, 2010

TypeId from table field

How to retrieve the typeId by a given FieldId? I didn't found a method doing this in AX, so I wrote it by my self:

int fieldId2TypeId(TableId _tableId, FieldId _fieldId)
{
    DictField dictField = new DictField(_tableId, _fieldId);
    int ret; // 32 bit length type
    ;
    if (dictField.typeId())
    {
        // extended type is given
        ret = dictField.typeId(); // dictField.typeId() is an int 16 range value
    }
    else if (dictField.enumId())
    {
        // enum type is given
        ret = dictField.enumId(); // dictField.enumId() is an int 16 range value
    }
    ret = ret << 16; // move enum or exteneded type information to left side 16 bit area


    ret = dictField.type() | ret; // combine left side 16 bits from typeId information with right side 16 bits from enum or extended type information


    return ret;
}

No comments:

Post a Comment