I came across a rather unpleasant reality on CRM options sets which is doing the right thing however causing a bit of a maintenance overhead if you want to extend CRM into other areas.
if we retrieve an option set with the below code:
returns an array of objects which may look like this:
Notice the sorting is done on the index value. Imagine you have 50 or more entries in one option set and once in a while you need to add a new entry and remove others, are you manually moving all index values to sort the option set alphabetically? if you have another entry starting with letter "A" then you need to change all none "A" to + 1 in the index value.
This would be painful and time consuming. I'm sharing a small piece of code that can do this for you if you face the same issue:
The results would then be sorted alphabetically:
Notice the index values now are not sequential and the text entries are alphabetically sorted.
Hope this was helpful, please leave your feedback.