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

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?


I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    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.

  • SGbron Profile Picture
    157 on at

    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. :(

  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    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

    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 . 

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