D365 Finance and Operations. How to get the numeric value of the extensible enum via X++.

There are 2 enum types in the system from an extensibility perspective – extensible and non-extensible. The difference is briefly explained here. There is a short recap below:

In D365FO enums that are not extensible keep the numeric value of each element in the metadata. 

However, extensible enums do not use metadata to store their numeric values. Instead, these values are stored in the database and are assigned dynamically by the database synchronization process.

The ENUMIDTABLE table stores the base enum ids, while the ENUMVALUETABLE table stores the numeric values assigned to every element of the base enum. While the ENUMIDTABLE table contains records for every base enum in the system, ENUMVALUETABLE is only populated for extensible enums.

In case we need to get the numeric value of the extensible enum the following method can be useful:

public Integer getEnumValue(str     _enumName,

                            str     _enumValueName)
{
   Integer     ret;

 

   if (_enumName && _enumValueName)
   {
      str sqlQuery = strFmt(@"SELECT ENUMVALUE from ENUMVALUETABLE
                            join ENUMIDTABLE on enumid = id
                            and ENUMIDTABLE.NAME    = '%1'
                            and ENUMVALUETABLE.NAME = '%2'",
                            _enumName,
                            _enumValueName);

 

       str result   =  ReleaseUpdateDB::statementExeQuery(sqlQuery);
       if (result)
       {
           ret = str2Int(result);
       }
   }
      
   return ret;
}

No comments:

How to run batch tasks using the SysOperation framework

Overview As you may know, the system has batch tasks functionality . It can be used to create a chain of operations if you want to set an or...