Can’t make |state| of content into type reference

How does one manipulate records within a handler?

if name of current application is "Script Editor" then
	tell application id "DNtp"
		set sel to selected records
		my performSmartRule(sel)
	end tell
end if

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			my flag(theRecord)
		end repeat
	end tell
end performSmartRule

on flag(theRecord)
	set state of theRecord to true
end flag

throws the error:

error "DEVONthink 3 got an error: Can’t make |state| of content id 18164 of database id 2 into type reference." number -1700 from |state| of content id 18164 of database id 2 to reference

The flag function needs a tell block like this:

on flag(theRecord)
	tell application id "DNtp"
		set state of theRecord to true
	end tell
end flag

Is this the complete & final script or will it be extended/revised? Because smart rules can change the flag without having to use scripts.

Following up on @cgrunenberg’s comment: state is a property of DEVONthink’s dictionary, not a generic property, so it needs to be in a DEVONthink tell block.

Thanks @cgrunenberg The script is much larger - it shells out to perl, extracts 1/2 dozen fields. Just started working on adding error handling and refactoring which led to function issue.

			try
				add custom meta data item 5 of the theArray as number for "Tax" to theRecord
			on error error_message number error_number
				log message "Error: Handler \"can't parse tax\""
				set tags of theRecord to tags of theRecord & {"Needs review"}
				set state of the theRecord to true
				set anyErrors to true
				--				my flag(theRecord)
			end try

Got it. Within each function the “work” with DT needs to happen inside its own tell block.

Thanks for the added context!

You’re welcome and yes, that’s true if you’re using DEVONthink specific classes and properties such as state.

tell application id "DNtp"
	set sel to item 1 of (selected records)
	display alert "" & my getdate(name of sel)
end tell

on getdate(recName)
	return (recName & " " & (short date string of (current date)))
end getdate

The handler here doesn’t require a DEVONthink tell block as there’s no DEVONthink-specific commands or properties being used or requested.
I hope that makes sense.

1 Like