having trouble inserting an item in an outline

hi,
im having trouble creating a child item of an already existing parent Item of an Outline View.

heres the code


on clicked theObject
	if name of theObject is "add" then
		set group_name to contents of text field "text1" of window "main"
		set ext_name to contents of text field "text2" of window "main"
		set outlineView to outline view 1 of scroll view 1 of window 1
		
		tell dataSource
			make new data column at end of data columns with properties {name:"Item"}
			make new data column at end of data columns with properties {name:"Identity"}
		end tell
		
		set item_list to contents of data cell 1 of every data item of dataSource
		log item_list
		set item_list to item_list as list
		
		if group_name is not in item_list then
			
			set parentItem to make new data item at end of data cell group_name of data item 1 of dataSource
			set contents of data cell "Item" of parentItem to group_name
			set contents of data cell "Identity" of parentItem to ""
			-- create child 
			set childItem to make new data item at end of data items of parentItem
			set contents of data cell "Item" of childItem to group_name
			set contents of data cell "Identity" of childItem to ext_name
			
			set data source of outlineView to dataSource
			set returns records of data source of outlineView to false
			set prefs to content of outlineView
			set contents of default entry "mem" of user defaults to prefs
			
		

--this is the bit i can't quite get,
	else		
set theData to data cell "Item" of data item group_name of data source of outlineView
			log theData
			set childItem to make new data item at end of theData
			set contents of data cell "Item" of childItem to group_name
			set content of data cell "Identity" of childItem to ext_name
		end if

if not (exists default entry "mem" of user defaults) then
			
			make new default entry at end of default entries of user defaults with properties {name:"mem", contents:prefs}
			set outlineView to outline view 1 of scroll view 1 of window 1
			set returns records of data source of outlineView to false
			set prefs to content of outlineView
			set contents of default entry "mem" of user defaults to prefs
		end if
	end if
	
	if name of theObject is "remove" then
		set outlineView to outline view 1 of scroll view 1 of window 1
		set selectedDataRows to selected data items of outlineView
		if (count of selectedDataRows) > 0 then
			tell window of theObject
				delete (item 1 of selectedDataRows)
		        end tell
		end if
	end if
	set a to content of outlineView

		set contents of default entry "mem" of user defaults to a
end clicked
		

sorry if its a bit long winded
any advice would be greatly appreciated
many thanks
truth

no worries, i solved it!
it’s probably a bit dirty but i can use a repeat rutine like so;


on clicked theObject
	if name of theObject is "add" then
		set group_name to contents of text field "text1" of window "main"
		set ext_name to contents of text field "text2" of window "main"
		set outlineView to outline view 1 of scroll view 1 of window 1
		
		tell dataSource
			make new data column at end of data columns with properties {name:"Item"}
			make new data column at end of data columns with properties {name:"Identity"}
		end tell
		
		set item_list to contents of data cell 1 of every data item of dataSource
		log item_list
		set item_list to item_list as list
		-- dirty little repeat rutine
		repeat with i from 1 to count of items of item_list
			set this_item to item i of item_list
			if this_item = group_name then
				set my_num to i as integer
				beep
				display dialog this_item as string
				
			end if
			
			
		end repeat
		
		
		if group_name is not in item_list then
			
			set parentItem to make new data item at end of data cell group_name of data item 1 of dataSource
			set contents of data cell "Item" of parentItem to group_name
			set contents of data cell "Identity" of parentItem to ""
			-- create child 
			set childItem to make new data item at end of data items of parentItem
			set contents of data cell "Item" of childItem to group_name
			set contents of data cell "Identity" of childItem to ext_name
			
			set data source of outlineView to dataSource
			set returns records of data source of outlineView to false
			set prefs to content of outlineView
			set contents of default entry "mem" of user defaults to prefs
			
		else
			set theData to data item my_num of data source of outlineView
			log theData
			set childItem to make new data item at end of theData
			set contents of data cell "Item" of childItem to group_name
			set content of data cell "Identity" of childItem to ext_name
		end if
		
		
		if not (exists default entry "mem" of user defaults) then
			
			make new default entry at end of default entries of user defaults with properties {name:"mem", contents:prefs}
			set outlineView to outline view 1 of scroll view 1 of window 1
			set returns records of data source of outlineView to false
			set prefs to content of outlineView
			set contents of default entry "mem" of user defaults to prefs
		end if
	end if
	
	if name of theObject is "remove" then
		set outlineView to outline view 1 of scroll view 1 of window 1
		set selectedDataRows to selected data items of outlineView
		if (count of selectedDataRows) > 0 then
			tell window of theObject
				delete (item 1 of selectedDataRows)
			end tell
		end if
	end if
	set a to content of outlineView
	
	
	set contents of default entry "mem" of user defaults to a
end clicked

seems to work ok,
let me know if it could be improved on
peace
truth