Creating collections from a selection

Let’s assume we have a table (table en field names are in Dutch which is historical) where a 1000 records match the next criteria. I want to put this in a collection but with English key names. Next function works perfect but is slow…

$vo_Temp:= New object (“company”;->[KLANTEN]FIRMA;“number”;->[KLANTEN]KLANT_NR;“deliveryDays”;->[KLANTEN]LEVERDAGEN)
$vc_Collection:=JSON Parse ( Selection to JSON ([KLANTEN];$vo_Temp);Is collection)

Then we have ORDA. Great but I could not rename the key’s…

ds [ Table name (->[KLANTEN])]. query ( Field name (->[KLANTEN]LEVERANCIER)+" = 1"). toCollection ( Field name (->[KLANTEN]FIRMA)+", “+ Field name (->[KLANTEN]KLANT_NR)+”, "+ Field name (->[KLANTEN]LEVERDAGEN))

What I could do is run through the collection and rename the key ;-(
Or do a COLLECTION TO ARRAY and then back again.

Has anyone a better idea?

I would use the ORDA approach and the map function of the collection.

$coll:=ds.KLANTEN.query("LEVERANCIER) = 1").toCollection("FIRMA,KLANT_NR,LEVERDAGEN")

MappingNamesFn is a callback function that performs the mapping of the names.
I can’t say anything about performance. Try it on your own.
It would be nice if entitySelection.toCollection could support the mapping like Selection to JSON. But Selection to JSON has the other disadvantage that it destroys the current selection of records.

Thanks, I will try this and see what the speed is. Could be a good solution for the time being. I think it will be fast because it’s in memory.

with 18 R3 you could consider to replace entitySelection.toCollection with entitySelection.extract()

This gives you what you want…


This is exactly what I did. I found the function but did not know it was there. Just for the other members:
Old way: 10425ms new way with .extract() 222ms.
Both cases where with an client server situation with two Macs. (not the fastest client)

What an improvement!

1 Like

There is only one thing missing if we want to make the routine generic. With toCollection you can pass an collection as parameter. This is not possible with .extract()
We can only pass parameters? Is that correct? With selection to array we have an ;* parameter to add multiple lines.


Yes, with the .extract() member method we must pass attributes as Strings.
I write down your suggestion.
Thank you.