Sorting optionset

Hello,

I have an option with value 1 to 999. On the form the option values are displayed as followed : 1, 10, 100 …2, 21…3, 31… etc…
However, I would like the option value to display as : 1, 2, 3…up to 999
Can someone tell me how i can get the option values ordered correctly

My DHIS2 version is 2.36.11

warm regards

Amza

@Amza ,

You can go to maintenance app and open the option set and select “Sort Manually” and re-arrange the options as per your need and save.
I know it’s a bit of a hassle doing this for 1000 options. :frowning:

Note: Clear the cache using cache cleaner app after making changes

Thanks,
Rithvik

2 Likes

@Amza ,

On another note, may I know the reason why you have configured an option set instead of a integer type data element and a program rule to check the range entered by user falls between 1-999?

Thanks,
Rithvik

1 Like

@rithvik thank you for your reply. Unfortunately, the manual sort is working only up to 50 optionvalues, it is not allowing me to go above
The reason why i wanted the option set is to avoid manual error typing

still not getting how to fix this error

Amza

1 Like

@Amza ,

One more trick is to export the option set and import it back. It is a bit technical to follow.
Please test this before performing this on production server

Steps

  • go to maintenance app → option set.
  • right click on the option set you intend to modify and click show details
  • You will see a popup. Click on the API URL.
  • It will open a new tab with the option set details.
  • Paste ?fields=*,options[*] after the URL.
  • Save this details by right clicking on the page and clicking save as
  • Save it as optionSet.json (any name would work but the extension should be .json)
  • Open this file in any editor of your choice.
  • Modify the sortOrder value corresponding to each option and save the file
  • Open Import/Export app and select metadata import
  • Upload the modified file and change the Merge mode to Replace
  • Click on start dry run, to validate the json for any errors.
  • If there are no errors for dry run, then click on Start Import.

This would update all the options with order provided in the file.

Clear cache and verify the order in the corresponding apps.

Thanks,
Rithvik

1 Like

@rithvik thank you so much. I have to tell you that this file, I uploaded it with the right numeric ascending order. I dont think export/correct/import will change anything

warm regards

Amza

@Amza ,

If you think the import has been done properly, then use the API call above to verify the same. If you see the sortOrder field is different than expected, then exporting-> correcting-> importing will fix the issue.

Thanks,
Rithvik

1 Like

2 posts were split to a new topic: Range expression not working in program rule

Hi Amza,
Have you tried naming the numbers 001, 010, 100…?

1 Like

@Amza ,

I have raised a PR for a fix. Let’s see how it goes.

@Gassim , any idea on the process of how to take this forward?

Thanks,
Rithvik

1 Like

Thank you @rithvik ! Sure, someone from the developers will review the pull request and take the required action. You will receive a notification if there’s a comment or an update. Following up for updates on this PR as well. Thank you!

Thank you @rithvik and @Gassim for following up on this issue. Let’s wait solution from developers.

warm regards,

Amza

1 Like

@rithvik: thanks so much for the PR! I’ll take a look and get back to you (I’ll follow up by early next week on the PR)

@Amza: thanks for reporting your issue. If you have a chance, can you let us know if you’re using this data element for aggregate or tracker data :pray:?

1 Like

I was also thinking you could potentially change the code to something characters, leaving the name to integers, then perhaps you could sort by code as a workaround.

1 Like

Thanks! Yes, same thought, but I didn’t test it! :smiley:

Hi there,

When I had an optionSet with more than 500 options inside, downloaded it as csv or json, for example

then change manually sortOrder as I need in Excel. It can be done really quickly and easily

and then updated back that optionSet. This is fastest way to solve you needs.

Regards,

2 Likes

Thanks @Ulanbek! @Amza could you please try this and report? (: