"can't get location of db id X" error w/ adapted Move script

Hi, I tried to adapt the “Move” script that can be added to DTPO through the extras palette so that instead of displaying the group/tag selector, the script would move the selected items to the root of the database of the selected items. Unfortunately, this is throwing the error:

I tried this in a few of my open databases, and “X” just adjusts for the respective database id #.

Here is the script as written; any input would be greatly appreciated!


(* 
Move the selected record(s) to the root of the database.
Adapted from version 20140112.1 of script `Move__Cmd-Ctrl-M`.
*)

try
	tell application id "DNtp"
		
		set theDatabase to current database
		set theSelection to selection
		if theSelection is {} then error "Please select something to move to the root of " & theDatabase & "."
		
		set fromPath to (the location of item 1 of theSelection) & (the name of item 1 of theSelection)
		
		set theDestination to the root of theDatabase
		
		repeat with thisItem in theSelection
			move record thisItem to theDestination
		end repeat
		
		-- Post the result to the Log
		set movedFrom to "Moved from: " & fromPath & " in " & theDatabase
		set movedTo to " -- Moved to: " & theDestination & " in " & theDatabase
		set theLogEvent to log message (movedFrom & movedTo) info "Move-to-Root Script"
		
	end tell
	
on error error_message number error_number
	if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	
end try

theDestination is not a string.

	get root of database id 4
--> parent id 2.147483645E+9 of database id 4

Neither is theDatabase.

get current database
-> database id 4

You can’t pass those value to the log because they are not strings. Also, you want to pass the name of those items.

	-- Post the result to the Log
set movedFrom to "Moved from: " & fromPath & " in " & (name of theDatabase)
set movedTo to " -- Moved to: " & (name of theDestination) & " in " & (name of theDatabase)
set theLogEvent to log message (movedFrom & movedTo) info "Move-to-Root Script"

I suggest you remove try-end try blocks when debugging code, so you can see better where things are failing.