Code, AX, How to read the Data Dictionary
How to read the data dictionary in axapta (dynamics ax).
static void HL_ReadDictionary2(Args _args)
{
/*
This little script creates an Excel .CSV (text) file of complete Data
Dictionary of current Axapta environment. If sorted you have a complete
list to search in, also field-types etc are specified. Took some
thinking to figure this out..
2007-10-22 /Henrik
*/
Dictionary dictionary = new Dictionary();
DictTable dt;
DictField df;
int j;
CommaIO out;
str sBaseType,sEnumType,sExtended,sLength;
container GetTypes(DictField _df)
{
EnumId eId;
DictType dType;
DictEnum de;
extendedTypeId eti;
str sBase, sEnum, sExtend;
Types eType = _df.baseType();
;
switch(eType)
{
case Types::AnyType : sBase = "AnyType"; break;
case Types::BLOB : sBase = "BLOB"; break;
case Types::Class : sBase = "Class"; break;
case Types::Container : sBase = "Container"; break;
case Types:
ate : sBase = "Date"; break;
case Types:
ateTime : sBase = "DateTime"; break;
case Types::Enum :
sBase = "Enum";
eId = df.enumId();
if(eId != 0)
{
de = new DictEnum(eId);
if (de)
sEnum = de.name();
}
break;
case Types::Integer : sBase = "Int"; break;
case Types::Real : sBase = "Real"; break;
case Types::Record : sBase = "Record"; break;
case Types::RString : sBase = "RStr"; break;
case Types::String : sBase = "Str"; break;
case Types::UserType : sBase = "UserType"; break;
case Types::VarString : sBase = "VarStr"; break;
case Types::void : sBase = "Void"; break;
}
eti = _df.typeId();
if (eti != 0)
{
dType = new DictType(eti);
if (dType)
sExtend = dType.name();
}
return [sBase,sEnum,sExtend];
}
;
// Creating new file with write access
out = new commaIO("C:\\temp\\Dictionary.csv","w");
// Setting up Record delimiters
out.outRecordDelimiter("\\r\\n");
out.outFieldDelimiter(";");
out.write( "!Table.Field", "BaseType", "Length",
"EnumType", "Extended" );
dt = dictionary.tableObject(dictionary.tableNext(0));
while (dt)
{
for(j=1; j <= dt.fieldCnt(); j++)
{
df = new DictField(dt.id(), dt.fieldCnt2Id(j));
[sBaseType, sEnumType, sExtended] = GetTypes(df);
if(df.stringLen())
sLength = int2str(df.stringLen());
else
sLength = "";
out.write( dt.name() + "." + df.name(), sBaseType,
sLength, sEnumType, sExtended );
}
dt = dictionary.tableObject(dictionary.tableNext(dt.id()));
}
out = null;
info("Dictionary read done!");
}