Sorting line items

Hi all

I have a portal with line items for a quote / invoice etc.

Users sometimes wish to insert a line item between two others so I have a sort field in which a line item number is auto incremented by 20 each time and then the whole portal sorted asc. by that. This means that a user can edit the number to sit between two others up to 19 times.

I would like to be able to build a button which moves lines up and down the list and think that I need to do something like getSelectedIndex -1 (or something), get the sort id for the PREVIOUS record in the index and give my record something like PREVIOUS sort id -1. Is this the right approach? and how do you select the record previous to the one you’re on?

Thanks for any help

Bevil

Hi Bevil,

How about using an array for this ?

Capture the sort id of the chosen portal row
Get all the sort ids from the related records and read them into an array
Sort the array elements by the sort id
Loop through until you are at the current record
Cycle backwards or forwards (depending upon whether you are moving up or down !) by element, pick up the previous or next sort id number and set the chosen record to that sort id +/- 1

Cheers
Harry