Preserving Sort Order while using Server

I have always kept my Check Book database records in the same order as my paper checkbook, because that makes it easier to locate and clear the records and balance my check book. After converting the database to use Server, the records no longer stay put, as Jim explained in the video training. So I have a field «Order in Paper CB» that I’m using to sort the records correctly.

I have a procedure “Sort the Order Properly” that simply sorts that field whenever I need to get the records in the correct order, including during .Initialize. I also have a procedure “Finalize the Order of the Database” that resets the numbering in that field when I have manually changed the order of the records. Both procedures are below.

My bookkeeper assures me that these procedures do not reliably keep the records in the correct order; sometimes records just jump to a different location. I think she’s using the procedures correctly, so I’m wondering if there is something incorrect in the procedures. Like, am I supposed to ForceSynchronize, or something? Any guidance would be appreciated. Here are the procedures:

Sort the Order Properly:

NoShow
Let TempBankNameLV = Bank
Field «Order in Paper CB»
SortUp
Select Bank = TempBankNameLV
EndNoShow
Field "Number"
ShowPage
LastRecord
Save

Finalize the Order of the Database:

NoShow
Let TempBankNameLV = Bank
SelectAll
Field «Order in Paper CB»
Sequence "1 1"
Maximum
Let MaxRecNumberLV = «Order in Paper CB» + 1
SetAutoNumber MaxRecNumberLV
RemoveSummaries 7
Select Bank = TempBankNameLV
EndNoShow
Field "Number"
ShowPage
LastRecord
Save

Assuming the values in the Order in Paper CB field are correct, the first procedure should get the database into the order you want. But remember, this is only temporary. It won’t stay in this order. Any time you synchronize, the order will possibly change. And it will synchronize automatically every time the database is opened.

It sounds like you might want to set up a ..PostSynchronize procedure in your database.

This procedure could call your procedure to Sort the Order Properly.

Hmm, I notice that your Sort the Order Properly procedure finishes with a save statement. I recommend that you remove that – especially if you call this from ..PostSynchronize. But even if you don’t, it accomplishes nothing. The only thing this procedure changes is the order of the records, and that order won’t be preserved when opening the database. So save does nothing except slightly slow things down.

Your Finalize the Order of the Database procedure does change the database, so save does make sense there.

The method you are using to calculate the maximum record number should work, but Panorama now has a simpler method for doing this. This method takes only a single line instead of 4, and doesn’t require adding and then removing a summary record.

setautonumber 1+aggregate({«Order in Paper CB»},"max")

If you haven’t heard about the aggregate( function, you can read about it here:

It’s one of my favorite features in Panorama X 10.2.

1 Like