Re-sorting a Browse
Sometimes, you have to sort the records in an embedded browse differently than the order in which they were entered. And, sometimes this order cannot be defined by using one of the fields in the child table. Here's what I did:
A list of "to do" items that is entered in one order, but is displayed in a different order.
A list in which you would like a space between every few lines, to make it more readable.
A sequence of operations that several people enter, that can be resequenced at will. This would also be applicable if a new operation is needed that has to fit in the middle of existing operations.
by John Zaleski
My reason for doing this was for a client's specific need. Every day, they manually entered certain data sent to them from their customers. One person entered the data and another might have to proof read it at a later time by comparing the data to the list or report submitted by their customer. The proof reading could be a bear of a task if the saved data was not in the same order as the report. On a regular basis, the data entry person would miss an item and as soon as that happened, the ability to view the data in the original order was gone. The logic in this sample application is the initial model of how I would eventually do it.
The logic behind the app is that the child table has two fields that store the line numbers when adding a new record. Line stores the line number that will be manipulated to display the line in a particular order. Line2 stores and maintains the original, unaltered line number. It is Line2 that allows the field rule to get the next sequence number when adding a new record, even though the display field (Line) may have been altered a number of times.
When doing the resequencing, the set displays the records in line-number order according to the set definition. If we simply read through the records in the set's order and changed the value of the field Line, you would get thrown into a program loop that would never end. Instead, I saved the record numbers of the child records in an array, and then read the array and retrieved the records by record number and changed the Line field with no problem. Reading the records this way in the background is not affected at all by rewriting the value of Line.
The Reset button simply takes the value of the field Line2 ( the original line number assigned to that record ) and writes it back to Line ( display line number ).
When running something like this in a multi-user environment, you have to take care that only one user at a time can access the parent record. Some additional logic would have to be added if you allowed the deletion of records and wanted to maintain sequence numbers with no gaps. The sequence order would be maintained if you deleted records the way it is written, but you would have gaps in the sequence number. With my client, the order was important and the gaps didn't bother them a bit.
This method can be used when you want to sort child record fields in a way that cannot be defined by a field or expression. Here are some possible applications:
•
•
•
There could be other applications that I haven't thought of. As you can see, this is not too difficult to implement.