18

Request


Add an Enum.GetName() method for the Enum datatype.

Similar to how we have an Enum.AsInteger() method.


Syntax


The Name of the Enum Value as a Text value := Enum.GetName()


Parameters

Enum

Type: Enum

An instance of the Enum data type.


Return Value

The Name of the Enum Value as a Text value

Type: Text


Examples


  local procedure Sample1(CustomerStatus: Enum "Customer Status")
  var
    EnumValueName: Text;
  begin
    EnumValueName := CustomerStatus.GetName();
  end;


  local procedure Sample2()
  var
    EnumValueName: Text;
  begin
    EnumValueName := Enum::"Customer Status"::"Gold Customer".GetName();
  end;


Explanation and Motivation


I am aware that we can currently use the following code to get the Enum value name, but it is very inefficient:


(See GitHub issue 5576: https://github.com/microsoft/AL/issues/5576#issuecomment-572456605)


  procedure GetEnumValueName(MyTestEnum: Enum TestEnum) Name: Text;
  var
    Index: Integer;
  begin
    Index:= MyTestEnum.Ordinals.IndexOf(MyTestEnum.AsInteger());
    MyTestEnum.Names.Get(Index, Name);
  end;


Instead I would like to get an instantaneous result, rather than needing an O(n) IndexOf-operation to get the enum name (impacting performance) and requiring multiple statements to achieve this.

So translating that example in what we would like to see:


  procedure GetEnumValueName(MyTestEnum: Enum TestEnum) Name: Text;
  var
    Index: Integer;
  begin
    Name := MyTestEnum.GetName();
  end;


Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team

Comments

R

It maybe would be better if the functions would be named GetValueName() and/or GetValueCaption() as suggested by someone on yammer.

Category: Development