Issue with the number sorting in the microflow

1
Hi, I am having trouble sorting (ascendingly) the file name in a microflow. Background: In the following image, the first column [16, 17, 18, 19…..26] is the attachment order, and the fourth column is the attachment name. When creating an sorting order, i am currently using the list sort option with ascending order with respect to attachment name.   Issue: The fourth column, the file name sort order is not working as expected. Expected behaviour: files should be sorted in [1.jpg, 2.jpg, 4.jpg, 5.jpg, 7.jpg, 10.jpg, 11.jpg. …….] Current behaviour: files are sorted in this way in currently [1.jpg, 10.jpg, 11.jpg, 12.jpg,…, 2.jpg, 20.jpg ….., 4.jpg,………..] Need help to fix this sorting irregularities.
asked
1 answers
2

The issue you are seeing is because the data in the fourth column is a String, so it is sorting asciibetically, not numerically. 

If you need it to sort numerically one option would be to create an additional attribute in your entity to hold the numeric value and sort by this. One way to set this attribute could be to create a before commit event handler that looks at the value of the attachment name, and tries to parse it into a numeric value with some string manipulation and the parseInteger function.
https://docs.mendix.com/refguide/parse-integer/

Hope this helps.

answered