web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Get Enum Name from Enum value (integer index value)

(0) ShareShare
ReportReport
Posted on by 89

I have one enum value: LedgerPostingType and I want to use this value and grab the same enum name value from InventAccountType. The thing is, the enum values with the same names on these two enums have different index values (i.e. InventProfit is enum value 93 on LedgerPostingType but value 8 on InventAccountType). I want to convert the enum index value of LedgerPostingType to the name value (InventProfit) and then grab this same enum from InventAccountType. See the code below for what i am trying to achieve (it doesn't compile).

{

str postingTypeForLookupName, inventAccountTypeForLookupName;

LedgerPostinType postingTypeForLookup = GeneralJournalAccountEntry.PostingType;


postingTypeForLookupName = SysDictEnum.index2Label(postingTypeForLookup);
inventAccountTypeForLookup = InventAccountType::postingTypeForLookupName;

}

Thanks in advance

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    You forgot to create an instance of SysDictEnum. Also, I believe a better approach will be refering to the element name and not the label. You can either use index2Symbol() method of SysDictEnum class, or a global function called enum2Symbol().

    Try something like this:

    str enumSymbol = enum2Symbol(enumNum(LedgerPostinType), postingTypeForLookup);
    
    SysDictEnum inventAccountDictEnum = new SysDictEnum(enumNum(InventAccountType));
    InventAccountType inventAccountType = inventAccountDictEnum.symbol2Value(enumSymbol);

    Don't forget to handle the situation when the corresponding enum element doesn't exist.

  • tristansenk99 Profile Picture
    89 on at

    Hi Martin,

    Thank you, this is exactly what I needed.

    I appreciate your help!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans