Tech Tip: OrderByMethod not sorting correctly
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: October 14, 2024
When working with the command ".orderbyMethod()", there may be an issue when testing out the sorting that the collection being returned will not be sorted correctly, despite the sorting method making logical sense. In this case, check the C_OBJECT declarations in the sorting method to see that the $0 has not been accidentally declared. Otherwise, the command may return an unchanged collection. This is because the sorting method for this command must return nothing, as it will use the "$1.result" instead.
//incorrect implementation C_OBJECT($0; $1) $1.result:=Num($1.value.PropertyName)<Num($1.value2.PropertyName) |
//correct implementation C_OBJECT($1) $1.result:=Num($1.value.PropertyName)<Num($1.value2.PropertyName) |