Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Get the value from my radio button.

Posted on by 26
Hello, 
 
I would assume this is a really simple things, but Ive been googling and searching and trying, and I cant manage to get the value from my radio button control (if there is an API somewhere where I can find this and more Id love a link). 
 
Ive made a form with a dialog pattern where I have the radio buttons populated from an enum, and then an okay/cancel button. When I press okay Id like to know what enum has been selected.
 
The best Ive been able to do at the moment is:
 
/info(int2Str(FormRadioButtonControl1.selection()));/
 
Which tells me what the number in the enum array it is. And I can probably use that (is there good way to get the actual enum value from the array number?), but I also assume there is a way to get the enum right away.
 
Another thing I noticed is that there are 4 values in my enum, and from my selection solution above the first one gives me 0, second 1, third 2, and the fourth give me 4. Why does it skip 3? Is this a problem, maybe selection is not doing what I think it is?
 
Thanks for help. 
  • Dushatar Profile Picture
    Dushatar 26 on at
    Get the value from my radio button.
    Thank you Martin Dráb and Layan Jwei. Both your suggestions work.

    Ive tried to mark your replies as answers, but when I do the site just get stuck loading. Not sure if there is a problem at the moment or something weird on my side. Ill try again tomorrow. 
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    Get the value from my radio button.
    If the control is bound to a data source field, use the field directly, such as myTable.MyField.
     
    If it's an unbound control, use selection(), as you do, but assign the value to a variable with the type of your enum. For example:
    MyEnum selectedValue = FormRadioButtonControl1.selection();
    That the numeric values of enum elements aren't consecutive isn't a problem. You normally don't need to (or should) work with the numbers. You should use enum elements.
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Get the value from my radio button.
    Hi Dushatar,

    Regarding your 1st question, I think you should be able to get the enum value by using this:
    info(FormRadioButtonControl1.valueStr());

    ​​​​​​​and if you would like an enum object then
    Enum enum; //replace this with your enum value
    Info(strFmt("%1",str2Enum(enum, FormRadioButtonControl1.valueStr())));
    ​​​​​​​
    For the 2nd question: there is no issue but to understand why, is the enum you are using, has the property "IsExtensible" as false?  if yes, then look at the enum value for each one, maybe it's marked 0,1,2,4
    Here's what I mean:





    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans