Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Check whether feature linked to enum value is enabled

(0) ShareShare
ReportReport
Posted on by 11
I would like to know if there's a recommended way to dynamically check whether a feature associated with an enum value is enabled.  For example, I am iterating over the SysModule enumeration values and for each enum value whose configuration key and feature is enabled, I'd like to perform a custom process.  
I have something like this: 
 
SysDictEnum sysDictEnum= new SysDictEnum(enumNum(SysModule));
int sysModuleIndex;
ConfigurationKeySet configurationKeySet = new ConfigurationKeySet();
configurationKeySet.loadSystemSetup();        
// Look at all of the Module enumerations
for (sysModuleIndex = 0; sysModuleIndex < sysDictEnum.values(); sysModuleIndex++)
{                        
    // We don't want the Ledger Module in the mix
    if (sysDictEnum.index2Value(sysModuleIndex) != SysModule::Ledger)
    {
        // if the module exists in the table as a column
        if (LedgerPeriodModuleAccessControl::accessLevelFieldName(sysDictEnum.index2Value(sysModuleIndex)) != '')
        {
            // If configuration key is enabled, then check the access level for the module
            if (isConfigurationkeyEnabled(sysDictEnum.index2ConfigurationKey(sysModuleIndex)))
            {
                str enumFeatureClassName = sysDictEnum.index2FeatureClassName(sysModuleIndex);
                // todo: check if the feature is enabled 
                // then do the thing 
            }
        }
    }
}
 
 
 
I see this article on feature management: 
https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/fin-ops/get-started/feature-management/feature-management-overview
It states to check whether a feature is enabled to do something like this: 
if (FeatureStateProvider::isFeatureEnabled(BatchContentionPreventionFeature::instance()))
However, I just have a string of the feature class name.  So I'm thinking to try to use DictClass and use it like so: 
 
str enumFeatureClassName = sysDictEnum.index2FeatureClassName(sysModuleIndex);
if (enumFeatureClassName)
{                                        
    info(strFmt('Feature class name: %1', enumFeatureClassName));
    DictClass featureClass = new DictClass(className2Id(enumFeatureClassName));
    if (featureClass)                                        
    {                                                                         
        boolean isFeatureEnabled = FeatureStateProvider::isFeatureEnabled(featureClass.callStatic('instance'));
        info(strFmt('%1 isEnabled: %2', enumFeatureClassName, isFeatureEnabled));
    }
}
 
 
This isn't working - the class ITMInboundTransportationManagementFeatureToggle does not have an instance method.  It also feels a bit over complicated which makes me wonder if I'm doing it wrong.  Is there a better way to check if a feature is enabled for an enum value?  
 
Thanks for any suggestions!
Adam
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Check whether feature linked to enum value is enabled
    Hi Adam,
     
    The classes linked to an enum value for checking if it is enabled or not, do have a public method called isEnabled(). These classes are different from the clases used to control feature management itself. You can try calling that method by creating an instance of the FeatureToggle classes using the DictClass class. 
    In theory, the feature class for enums can also have other logic than checking feature management.
     
     
  • Community member Profile Picture
    Community member 11 on at
    Check whether feature linked to enum value is enabled
    I tried formatting my code with the "insert code snippet" button but it kept removing the spacing so I changed it to a block quote.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans