AL icon indicating copy to clipboard operation
AL copied to clipboard

Get value of enum

Open ajkauffmann opened this issue 5 years ago • 5 comments

I would like to be able to get the value of an enum. Currently, I only can get the corresponding number or the caption, but not the value itself.

Imagine I do have an enum like this:

enum 50000 "Customer Level" { value(0; NONE) { Caption = ''; } value(1; BRONZE) { Caption = 'Bronze level'; } value(2; SILVER) { Caption = 'Silver level'; } value(3; GOLD) { Caption = 'Gold level'; } }

And now I have a field of type enum "Customer Level" with value SILVER. How can I get that value out of the field into a text variable? If I do Format(MyEnumField) I get the caption 'Silver level'. There is no way to get the programmatic value 'SILVER'.

ajkauffmann avatar Nov 15 '18 15:11 ajkauffmann

For what purpose do you want to be able to do this? Not saying there might not be a good reason for it, but I was wondering what you are trying to achieve. :wink: Sidenote, if I recall correctly, using the Format function with an Option variable results in the same behaviour.

As I see it, the names are just aliases/identifiers for the valid options for the enum type. However, it's too bad that there isn't any way to retrieve the numeric values, which makes the enum type only useful for usage within extensions 'internally'. See also #3567 with some other suggestions for improvements on this.

So more generally, I think it would be nice to have some built-in functions that can be used with the enum type. As I understood from the replies to #3567, there are 'some' plans to have this improved in a future version. Hope to hear whether there is any update on this. :smiley:.

rvanbekkum avatar Nov 17 '18 10:11 rvanbekkum

Hi, I think you can use format(enum, 9) to get a language independent value. But I don't remember if it is the integer value or the symbol string.

BrianThorChristensen avatar Nov 20 '18 05:11 BrianThorChristensen

@ajkauffmann , I've added some proposals for Enums at #3567

JavierFuentes avatar Nov 24 '18 18:11 JavierFuentes

I think this is obsolete, as nowadays these functions on Enums and FieldRefs should enable determining the name text image

dzzzb avatar Jun 13 '22 10:06 dzzzb

Maybe, but what about to get the Captions or to be able to iterate using FOR and FOREACH without FieldRefs?

You can see my proposal here...

Many work to do with Enums yet I think...

JavierFuentes avatar Jun 14 '22 12:06 JavierFuentes