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

Notifications

Announcements

No record found.

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
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

    the solution I see as per below

    create one more new field as you want with type option and transfer all the data from the old field to new field and of course you need to write a logic in that way the result you want.

    after that you can delete the old field

    not sure if it’s ok for you

    Thanks

  • Suggested answer
    YUN ZHU Profile Picture
    95,679 Super User 2025 Season 2 on at

    Hi, If the user just wants to sort on selection. You can hide this field on the page.
    Create a new Option field, for example, B field " ,Cloud,hybrid,OnPrem".

    When B validates, A also assigns the corresponding value.

    For example, 

    if B = B::Cloud then

     A := A::Cloud

    ........

    In this way, only one page needs to be modified.

    Hope this helps as well.

    Thanks

    ZHU

  • Maddin Profile Picture
    30 on at

    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

  • Suggested answer
    YUN ZHU Profile Picture
    95,679 Super User 2025 Season 2 on at

    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

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    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.

  • Maddin Profile Picture
    30 on at

    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,708 Moderator on at

    Use FORMAT function format(yourfieldname::value)

  • Maddin Profile Picture
    30 on at

    In that way it does not work:

    1727.Optionswerte.PNG

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans