# bug foundset sort

**URL:** <https://forum.servoy.com/t/bug-foundset-sort/15781>\
**Category:** Classic Servoy\
**Created:** [April 5, 2012, 4:01pm UTC](https://forum.servoy.com/t/bug-foundset-sort/15781 "2012-04-05T16:01:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [April 5, 2012, 4:01pm UTC](https://forum.servoy.com/t/bug-foundset-sort/15781/1 "2012-04-05T16:01:46Z")

</div>

Hi, we noticed a bug for quite some time in Servoy 5 for which we have an easy workaround. Now I thought is a good time to share it with you :

Scenario :

\_fs = databaseManager.getFoundset(‘user\_data’, ‘some\_table’)  
\_fs.sort(‘sortfield1 asc, sortfield2 asc’)  
\_fs.loadAllRecords()  
var \_max = databaseManager.getFoundSetCounf(\_fs)  
for (var i=1; i\<=\_max; i++) {  
\_fs.setSelectedIndex(i)  
// do something nice like simulate an aggregrate…  
}

How can this go wrong ? ![:?]( "Confused")

Something goes wrong when \_fs index 200 and \_fs index 201 have the **same values** for sortfield1 and sortfield2. Yes, the famous Servoy foundset 200…  
In that case the \_fs index 201 data is identical to \_fs index 199 data including pk value !! Record 199 seems duplicated in the foundset.

Workaround : add the pk field to the sort and the foundset is ok…

You can imagine this bug can cost some debug hours to discover…

Regards,

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [April 5, 2012, 5:20pm UTC](https://forum.servoy.com/t/bug-foundset-sort/15781/2 "2012-04-05T17:20:03Z")

</div>

Lambert,

Firstly, I want to thank you for posting your findings. I have seen this behavior before but could not pin-point the source (nor did I have the time to investigate). And, yes, I believe you put in an inordinate amount of time to discover this bug (again, thank you).

You definitely should post your discovery on the support site: [http://www.servoy.com/s](http://www.servoy.com/s)

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [April 5, 2012, 5:41pm UTC](https://forum.servoy.com/t/bug-foundset-sort/15781/3 "2012-04-05T17:41:42Z")

</div>

owww wow, that’s tricky indeed, +1 to create a ticket!!

---

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [April 5, 2012, 6:29pm UTC](https://forum.servoy.com/t/bug-foundset-sort/15781/4 "2012-04-05T18:29:57Z")

</div>

Ok, [https://support.servoy.com/browse/SVY-1975](https://support.servoy.com/browse/SVY-1975)

Regardjes,
