20

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
New
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

I came here today to request this change, I really hope it happens.As others have said on Yammer maybe a distinction between the Enum Type and the Value should be made such as:ValueName := MyEnumVar.GetValueName();ValueCaption := MyEnumVar.GetValueCaption();EnumName := Enum::"My Enum".EnumName();EnumCaption := Enum::"My Enum".EnumCaption();as I think we should have some more abstract functions like we do with tables, pages, and reports.Whatever we could have, it'd be far more readable and maintainable conceptually thanNameValue := "My Enum".Names().Get("My Enum".Ordinals().IndexOf(MyEnum.AsInteger()));(I did try putting these in code blocks but got the error "We have encounter some malicious input. Please remove that and try again)

Category: Development

R

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

Category: Development