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:

Ax 2012 data upgrade in Tier-1 development environments(CHE). A parameter cannot be found that matches parameter name “TrustServerCertificate”.

When I ran data upgrade using Data Upgrade 10.0.41 package, I faced an issue: Executing step: 3 GlobalUpdate script for service model: AOSSe...