Dynamics Search Engine

Saturday, May 24, 2008

Provide Base Enum name and get the number of elements through X++

In this article I will tell you how the get number of elements of a Base Enum...
Prerequisite: You should have basic programming knowledge of X++.

I applied it on Ax 3.0

You can provide the base enum name directly using global method fieldnum() or you can provide it in a string using method fieldname2id() where you need to give table id and fieldname.

1) Open your Ax application then AOT.
2) Go to Jobs node and create a new job. Rename the job if you need. I renamed it to DictEnumElements.
3) Now write the following lines...

static void DictEnumElements(Args _args)
{

DictEnum de;
DictField df;
;
df = new DictField(tablenum(SalesTable),fieldname2id(tablenum (SalesTable),'SalesType'));

if(typeof(df.type()) == Types::Enum) //checks if Type == Enum
{
de = new DictEnum(df.enumId());
info(int2str(de.values()));
}
else
info('Not Enum type');
}

4) Now run the job and you will get the number of elements of the base enum 'SalesTypes'

No comments:

Post a Comment