Sunday, August 9, 2009

Type of Anytpe enum

Normaly you try to avoid using AnyType variables, but sometimes you are forced to use them. When you use a AnyType enum and you want to cast it to it’s actual data type, be sure you cast it to the right type to prevent stack-traces. You can get the enumId from a AnyType-enum by using the DictEnum::value2id(AnyType _value) -function. Then you can compare it with the enumnum(EnumType) to check if it is the right type.

In code this check could look like this:

static void testAnyTypeEnumCasting(Args _args)
{
DocumentStatus docStatus;
Anytype any = DocumentStatus::Invoice;
;
switch (DictEnum::value2id(any))
{
case enumnum(DocumentStatus) :
docStatus = any;
break;
case enumnum(...) :
...
}
}

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...