Hi,
I need to use str2enum function. The thing is I’ve got the Enum Id but I can’t convert it into Enum. I can’t declare the enum type as it will be dynamic and vary according to the data input.
SysDictTable dictTable;
DictField dictField;
EnumId enumId;
int fieldId
;
dictTable = SysDictTable::newName(“UploadTest”);
fieldId = dictTable.fieldName2Id(“ABCModel”);
dictField = new DictField(tableName2Id(“UploadTest”), fieldId);
enumId = dictField.enumId();
while Str2Enum(enum type, str text). the first argument is an enum, yet I can’t find a way to convert a particular EnumId into Enum.
Thanks in advance.
Hello Ronaldwiley,
If you want to get the name of the enum through the Id of any enum then you can use the enumId2Name method of the Global class as shown in the below job:
Global::EnumId2Name Method: client server public static identifiername EnumId2Name(int id)
static void enumId2NameFuncUse(Args _args)
{
DictTable dictTable;
DictField dictField;
EnumId enumId;
int fieldId;
Name enumName;
;
dictTable = new DictTable(tablenum(AssetTable));
fieldId = dictTable.fieldName2Id(“AssetType”);
dictField = new DictField(tablenum(AssetTable), fieldId);
enumId = dictField.enumId();
if (enumId)
{
enumName = enumId2Name(enumId);
box::info(strfmt("%1", enumName));
}
}
As far as enum declaration is concerned: All variables must be declared before they can be used. X++ does not allow variable declarations to be mixed with other X++ statements; variables must be declared before X++ statements. You should separate variable declarations from the rest of your code with a semi-colon (
on a separate line, at the end of the declarations:
int i;
Also the function str2Enum: Converts a text string into an enumerated text of the type specified by _type.
enum str2Enum(enum _type, str _text)
Return Value: An enumerated text of type _type that has the name _text.
The following example returns the enumerated text Current.
static void str2EnumExample(Args _arg)
{
BankAccountType bat;
;
bat = str2Enum(bat,“Current”);
}