data migration

hi!

how can I copy data from oldtable1 to newtable1 if there is a duplicate record and its child records using servoy foundsets?

contact
-idcontact
-name

phone
-idphone
-phonenumber
-idcontact

current data contents
idcontact name idphone phonenumber
1 servoy 1 12345
2 dell 2 23456
3 intel 4 34567

old data
idcontact name idphone phonenumber
1 hp 1 98765

new data should have
idcontact name idphone phonenumber
1 servoy 1 12345
2 dell 2 23456
3 intel 3 34567
4 hp 5 98765
where: idcontact became 4 because 3 is the max while idphone became 5 because 4 is the max
the old data is stored in tablename.xml format.