Fetching data-type of fields in table using Axapta

Does anyone know how to get data type of fields using Axapta. I am fetching the field names as follows:

using (axRecord = ax.CreateAxaptaRecord(tableName))
{
string toPrint = “”;
int i = 1;
while ((fieldName = axRecord.get_FieldLabel(i).Trim()) != “UNKNOWN”)
{
toPrint += fieldName + Environment.NewLine;
i++;
}
MessageBox.Show(toPrint);
}

Thanks in advance!

Try The dictfield object. New dictfield(tableid, fieldid) SebDra

SysDictField class is the right way if you want details about X++ types.

But if you just need to know .NET types, you can simply call GetType() on returned values:

Type type = axRecord.get_Field(i).GetType();

There is a problem with the .NET approach. The field id may be different and not in sequence. Is there any way to obtain field ids using only .NET?

I am calling DictTable.fieldNext function from Axapta.CallStaticMethod(). But its throwing an exception saying “DictTable not initialized”.

Code as follows:

try{

ax.CallStaticClassMethod(“DictTable”, “fieldNext”,“1”);
}

Am I going the right way. My idea is to get information of fields like name, data-type and if it is a primary key without writing any code in X++. Can I fetch this information using only Axapta class in .NET Business connector?

The .NET example expects that you’re able to get value (I used your own code to demonstrate GetType()). If you don’t know how to get value, you can’t ask for its type, of course.

fieldNext() is not a static method, you have to create an instance of the DictTable first. Your code can’t work even theoretically, because it doesn’t say for what table fields should be obtained. I really recommend testing your code in X++ editor first, it would be refused by compiler.

By the way, what version of AX do you use? You have some other ways in AX2012.

I’m using 2009 version.

Update : I’m using the following code :

dt = new DictTable(tID);
if (dt)
{
counter = dt.fieldNext(counter);
while (counter)
{
df = dt.fieldObject(counter);
if (df)
{

fields = conIns(fields,1,df.baseType());

}
counter = dt.fieldNext(counter);
}
}

But i’m getting a Types Enumeration value. ( an integer). How do I get the value in string? e.g. any method like “str fieldType = getFieldTypeName(type_id)” ??

You can convert enum to string by enum2str().

If you want information about extended data types and enums, don’t use baseType() - use type() together with typeId(), enumId(), extendedTypeId2name() and enumId2name(), for example.