Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum returning caption instead of value #5576

Closed
AntoineTal opened this issue Jan 3, 2020 · 2 comments
Closed

Enum returning caption instead of value #5576

AntoineTal opened this issue Jan 3, 2020 · 2 comments

Comments

@AntoineTal
Copy link

Describe the bug
When trying to use an enum and send it to an API, it is sending the caption instead of the value.

To Reproduce

Have an enum :

enum 50000 TestEnum
{
    Extensible = true;

    value(0; "")
    {
        Caption = '';

    }
    value(1; "AF")
    {
        Caption = 'AF - Actualité financière';
    }
    value(2; "CN")
    {
        Caption = 'CN - Sinistres';
    }

Use this enum in a table :


table 50000 CompanyTheme
{
    Caption = 'CompanyTheme';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; ID; Integer)
        {
            Caption = 'ID';
            DataClassification = CustomerContent;
            AutoIncrement = true;
            Editable = false;
        }
        field(2; "Thème"; Enum TestEnum)
        {
            Caption = 'Thème';
            DataClassification = CustomerContent;
        }

In a codeunit,

`var
CompanyTheme : Record CompanyTheme 

this line is the issue : 

payload := '&DateDebut=' + dateDebut + '&DateFin=' + DateFin + '&Theme=' + FORMAT(CompanyTheme."Thème");`

Expected behavior*

I think CompanyTheme."Thème" should return AF and not "AF - Actualités financières" because I need to send to my API only the AF and I don't think just cutting the first 2 string of Theme is the right idea...

5. Versions:

  • AL Language: 4.0.209944
  • Business Central: 15.1 (and 15.2)
@esbenk
Copy link
Contributor

esbenk commented Jan 9, 2020

This is by design. The Format works the same way as for Option fields to ensure backwards compatibility.

The scenario is perfectly valid though. Unfortunately we don't have an ideal way of doing this right now. From Version 4.0 of AL you can do something like

    procedure GetEnumValueName(e: enum TestEnum): Text;
    var
        index: Integer;
        name: Text;
    begin
        index := e.Ordinals.IndexOf(e.AsInteger());
        e.Names.Get(index, name);
        exit(name);
    end;

    procedure GetEnumValueName(fref: FieldRef): Text;
    begin
        exit(fref.GetEnumValueNameFromOrdinalValue(fref.Value));
    end;

@AntoineTal
Copy link
Author

Thanks for the response,

That seems to be a long way to do something that should be easily done but it works for now! thanks for the tips 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants