I can return changed filtered data to the source, but looking for tips

Hi all,

Here’s what I’ve got:
In one tab, I have a table that shows the source data I am filtering into a table in another tab. I needed a way to change the source data when the filtered data changed, so I put an id number column in each table to hold a random large number (I should probably set up a property to just count up from 1). When the data in the filtered result changes, the script looks at the filtered result’s id, finds the match in the source and sends the changes back to the source.

-- source data is in a table view in a separate tab view item from the filtered table
       set sourceData to data source of table view "sourceData" of scroll view "sourceData" of tab1
	set sourceRow to make new data row at end of data rows of sourceData
	--here I set a large random number to the idNumber data cell of the row to be referenced later.
	set contents of data cell "idNumber" of sourceRow to random number from 0 to 99999999
	--the following is the table showing the filtered results
	set filterTable to table view "filterData" of scroll view "filterData" of tab2
		--the following handler filters the source data according to the contents of some text fields
		--(not shown) then returns the filtered results to filterTable
my filterDataSource(filterTable, sourceData)

--the following is set for when the cell value of the filtered table is changed.
on cell value changed theObject row theRow table column tableColumn value theValue
	--first I get the id number of the filtered result.
set idNumberOfFiltered to contents of data cell "idNumber" of selected data row of theObject
	set theRow to selected data row of theObject
	--next I get the idNumber column of the source data as a list
	set idNumbersDataColumn to items of data column "idNumber" of sourceData as list
	-- then I determine the position on that list of the matching id number from the selected row of the filtered results
	set recordNumber to my list_position(idNumberOfFiltered, idNumbersDataColumn)
	--now I have a reference for the filtered result's source
	set dataRecord to data row recordNumber of sourceData
	--then I set the content of every data cell of the source to the same of the filtered result
	--(I should probably only update the matching cell)
	repeat with j from 1 to count of every data cell of theRow
		set name of data cell j of dataRecord to name of data cell j of theRow
			set contents of data cell j of dataRecord to contents of data cell j of theRow
		end try
	end repeat
end cell value changed

There has to be a better way to do this. Any tips would be greatly appreciated.