Script newbee needs help

Hi!

I’ve some wired (for me :wink: ) scripting problems.
In an smart group folder I collect entries of some groups and put them to a new one.
the wired thing is: on creation of the smart group the collection succeeds,
but on an update it fails. any idea why?


-- Smart Group for open Jobs

on run
	try
		set scriptPath to POSIX path of (path to me)
		if scriptPath ends with "/" then set scriptPath to ""
		tell application "DEVONthink Pro"
			my triggered(create record with {name:"@ ToDo", type:group, attached script:scriptPath})
		end tell
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "DEVONthink Pro" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end run

on triggered(theRecord)
	try
		tell application "DEVONthink Pro"
			if type of theRecord is group then
				tell the root of the current database
					get every child where the name starts with ¬
						"@" and the type is group ¬
						and the name does not start with "@ "
				end tell
				set theTodoGroups to the result
				repeat with theGroup in theTodoGroups
					repeat with theItem in every child of theGroup
						replicate record theItem to theRecord
					end repeat
				end repeat
			end if
		end tell
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "DEVONthink Pro" message error_message
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end triggered

The script doesn’t remove replicants if necessary and doesn’t check if the smart group contains already replicants.