web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How do I sort existing option values alphabetically?

(0) ShareShare
ReportReport
Posted on by 30

Hello guys,

here is what I'm going to do:

I have a field "Type" and it has option as data type.

As option values I have " ,hybrid,OnPrem,Cloud".

Now the users are bothered by the fact that the values are not sorted alphabetically and want the values to be displayed in the selection:

" Cloud,hybrid,OnPrem".

However, I have many orders in which the field is already filled.

Now I need a procedure that allows me to change the option values.
If I simply change the order of the options as desired, the result is that the type that was previously "hybrid", for example, is now "Cloud".

The integer value has not changed as a result of the sorting.

How should I solve this?

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: How do I sort existing option values alphabetically?

    Then you can try to use the integer value of the option you want to refer to.

    The options are zero indexed. So the first option is 0 and so on.

  • Maddin Profile Picture
    30 on at
    RE: How do I sort existing option values alphabetically?

    That is also not working.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: How do I sort existing option values alphabetically?

    And it is two single quotations marks that should be used - just to be clear on that.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: How do I sort existing option values alphabetically?

    Try using ::'' instead to indicate an empty string

  • Maddin Profile Picture
    30 on at
    RE: How do I sort existing option values alphabetically?

    In that way it does not work:

    1727.Optionswerte.PNG

  • Suggested answer
    Nitin Verma Profile Picture
    21,664 Moderator on at
    RE: How do I sort existing option values alphabetically?

    Use FORMAT function format(yourfieldname::value)

  • Maddin Profile Picture
    30 on at
    RE: How do I sort existing option values alphabetically?

    Hello folks,

    I have now made a new field 2 next to my old field with the non-alphabetically sorted values, whose values are now sorted alphabetically.

    With a report I now assign the value from the old field to the new field 2 (OnAfterGetRecord()).

    When I run the report, it does not assign the correct value, but the integer value again.

    What am I doing wrong?

    Optionswerte.PNG

  • Suggested answer
    Nitin Verma Profile Picture
    21,664 Moderator on at
    RE: How do I sort existing option values alphabetically?

    Yes Zhu is right here, as also mentioned in my answer earlier please write your logic carefully while transferring the data to new field.

    Thanks.

  • Suggested answer
    YUN ZHU Profile Picture
    91,851 Super User 2025 Season 2 on at
    RE: How do I sort existing option values alphabetically?

    Hi, Do not assign directly.

    Try the following:

    if "Service Header"."Worktype" = "Service Header"."Worktype"::hybrid then

           "Service Header"."Worktype 2":=  "Service Header"."Worktype 2"::hybrid;

    Because you have more types, you can use Case statements.

    More details: 

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-al-control-statements#case-statements

    Hope this helps.

    Thanks.

    ZHU

  • Maddin Profile Picture
    30 on at
    RE: How do I sort existing option values alphabetically?

    Unfortunately, my logic does not work as I had hoped.

    I have now created a new field (ID: 50059) and transferred the value from the old field to the new field via a report.

    But now I have a different value in the new field than in the old one (ID: 50053).

    Art.PNG

    How do I have to adapt my logic?

    "Service Header"."Worktype 2" := "Service Header"."Worktype";

    Thank you

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,844

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,010

#3
Sumit Singh Profile Picture

Sumit Singh 2,815

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans