Skip to main content

Notifications

Community site session details

Community site session details

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

Retrieve enum value from unbound enum control

(0) ShareShare
ReportReport
Posted on by 157

Hello, I have an unbound control named ElementType

The original control have 7 values inside but i have created a new dialog and on this dialog, according the selected record I fill the enum with different values everytime. 


public void init()
{     

        ElementTable selectedRecord = this.args().record();
        Set enumSet = new Set(Types::Enum);
        
        switch (selectedRecord.ElementType)
        {
                case ElementType::Object:
                case ElementType::Milestone:
                    enumSet.add(ElementType::Task);
                    enumSet.add(ElementType::Milestone);
                    break;

                case ElementType::Task:
                    enumSet.add(ElementType::Task);
                    enumSet.add(ElementType::Milestone);
                    enumSet.add(ElementType::Line);
                    
                    break;

                default:
                    break;
        }
        
         sysFormEnumComboBox::newParameters(element,element.controlId(formControlStr(ElementTypeSelectionDialog,ElementType)),enumNum(ElementType),enumSet, "@Test:ElementType");

         super();
}



It works fine but now i want to retrive this value in CloseOk. The problem is that when I am using  any2enum(ElementType.selection() it return the value of the original enum. 

For example as you see I add three values (Task, Line, Milestone). But when I try to get the value with the above line it return the index of the first value of the enum that is not declared in the set. 

I tried to do it by comparing the selection with specific values (0,1,2) but the problem there is that the set is dynamic and everytime the set can be filled with different values. So that does not make sense. 

Do you have anything in mind that can solve this issue?


  • SGbron Profile Picture
    157 on at
    RE: Retrieve enum value from unbound enum control

    Hello Girish

    Exactly that was the solution:

    str enumName = ElementType.valueStr();
    
    SysDictEnum dictEnum = new SysDictEnum(enumNum(ElementType));
    
    ElementType elementTypelocal = dictEnum.symbol2Value(enumName);


    thank you very much for the help . 

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Retrieve enum value from unbound enum control

    Please refer to the below article which uses SysDictEnum class to get the value.

    https://axnews.blogspot.com/2020/08/convert-enumname-to-label-in-ax2012.html

    Similary you can use SysDictEnum.valueToName() method to get the Enum element name.

    Thanks,

    Girish S.

  • SGbron Profile Picture
    157 on at
    RE: Retrieve enum value from unbound enum control

    Hello Girish

    Yes of course. It was the first thing that I tried.

    It seems that returns the correct value but it returns the label.

    So that is not a solution. :(

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Retrieve enum value from unbound enum control

    Hi Christos,

    Have you tried using the valueStr method of FormComboBoxControl - It will return the string value of that control. Try using that and let us know the outcome.

    Thanks,

    Girish S.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 501 Most Valuable Professional

#2
Saalim Ansari Profile Picture

Saalim Ansari 313

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 310

Overall leaderboard

Product updates

Dynamics 365 release plans