Lookup table not ordering alphabetically

commcare

In my lookup table I have options A, B, C, D, Other (in that order) but as multiple choice answers they appear Other, A, B, D, C. I assume that it is ordering the choices alphabetically based on the UID assigned to each field.

Is there a way around this?

Best Answer

The sort()function will help you order the options in this case. This function can sort a space-separated list of strings.

For instance: Syntax: sort("a b c d", true()) Examples:

sort("4 2 1 5 3 2") `--> "1 2 2 3 4 5"`
sort("4 2 1 5 3 2", true()) `--> "1 2 2 3 4 5"`
sort("4 2 1 5 3 2", false()) --> "5 4 3 2 2 1"

Another option is the sort-by() function which can be used to sort 1 list based on another.

Full documentation on how to use these functions can be found here:

Please note that this function is only available for CommCare mobile version 2.38 or later.