Issue moving records in table view

We have a form of style Master → Details, where Details are shown in a “table view” form
Records of Details form are divided in two groups: Simple and Compound.
Compound ones are formed by one or more Simple records making a kind of block of parent and children, each child has the ID of its parent (parent_id)
Simple and Compounds records can be in the Details list at the same time.

Actually we have a routine wich moves records up and down in Details list, the way to do that is copy the content of a record to the next one.
The problem is with Compound records, because parent and children have to be moved as one, when doing this the rest of Simple record in a moment
pass through positions of Compound records taking ID of their parent, when movement is finish we try to clear parent_id of Simple moved record
but this doesn’t work, once it gets the parent_id it cannot be removed, neither assigning null nor any other value.

IDs are managed with “db identity” and autosave is set to false, at moment of saving we use startTransaction - commitTransaction.
Because of this, when working on moving Details, IDs have the form dbIdentValue123…, we don’t know if that affects on something.

In summary we have:

Master

  • master_id
  • info

Details

  • detail_id
  • master_id
  • position
  • info
  • parent_id (for children of Compound records)

Notes:

  • Simple records and parent of Compound records should have parent_id field set to null.
  • To copy records we use databaseManager.copyMatchColums(srcRecord, destRecord) function.
  • In other cases where Details have only Simple records they work perfectly.

We’d like to know if there’s a better way to do this, or if we can avoid that copyMatchColumns function copies a particular field and that field
will be copied manually in case of needed. We tried to do that with third function parameter set first in true, after with ‘parent_id’
an it still doesn’t work.

Hi Danny,

first welcome to the wonderfull world of Servoy and to this forum! :)

We do this also, but doing it by a sortorder_id column

the only think you have to do than, is change the sortorder_id of your current record and the previous & next sortorder_id (that depends if you move the record up or down)

after that, just sort on that sortorder_id and your are done!

Hi Harjo,

Thanks for the welcome… :)

We also have a column for sort the Details list, “position” column, the solution you propose works well, the only problem we had to implement it is autosave set to false, therefore the sort method doesn’t work because there are records not saved yet.
This is why we don’t use this method at first, but right now we found a way to implement it: we save records (databaseManager.saveData) when moving
a record and set a flag to true, this way allow us to do a normal sort by “position” column, at the moment of cancelling creation of Master → Details
if that flag is true we delete the record.

Well, now it works perfectly, thanks for the reply…