Get the DEVONthink item in app script

Hi, I try to write an automate to add mail to DEVONthink and send the link to reminder simultaneously. I just add up the two sample scripts. However, it doesn’t work because the script do add mail but not return the path or link of the new item. The second script doesn’t know the desired item. Is it possible to make it work somehow? Thanks!

Please post your scripts as code, ie included in backticks like so
```
Code
```

That allows other people to copy and test it

:joy:actually nothing.
I just want to add up

property pNoSubjectString : "(no subject)"

tell application "Mail"
	try
		tell application id "DNtp"
			if not (exists current database) then error "No database is in use."
			set theGroup to preferred import destination
		end tell
		set theSelection to the selection
		set theFolder to (POSIX path of (path to temporary items))
		if the length of theSelection is less than 1 then error "One or more messages must be selected."
		repeat with theMessage in theSelection
			my importMessage(theMessage, theFolder, theGroup)
		end repeat
	on error error_message number error_number
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

on importMessage(theMessage, theFolder, theGroup)
	tell application "Mail"
		try
			tell theMessage
				set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
			end tell
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			set theAttachmentCount to count of mail attachments of theMessage
			tell application id "DNtp"
				if theAttachmentCount is greater than 0 then set theGroup to create record with {name:theSubject, type:group} in theGroup
				set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in theGroup
				perform smart rule trigger import event record theRecord
			end tell
			repeat with theAttachment in mail attachments of theMessage
				try
					if downloaded of theAttachment then
						set theFile to theFolder & (name of theAttachment)
						tell theAttachment to save in theFile
						tell application id "DNtp"
							set theAttachmentRecord to import theFile to theGroup
							set unread of theAttachmentRecord to (not theReadFlag)
							set URL of theAttachmentRecord to theSender
							perform smart rule trigger import event record theAttachmentRecord
						end tell
					end if
				end try
			end repeat
		on error error_message number error_number
			if error_number is not -128 then display alert "Mail" message error_message as warning
		end try
	end tell
end importMessage

and

property pDaysIntoFuture : -1 -- Created to do will have a due date n days in the future
property pPrefix : "Reminder" -- Prefix for the created to do item
property pDelays : {{displayname:"No due date", value:0}, {displayname:"Custom…", value:-1}, {displayname:"Tomorrow", value:1 * days}, {displayname:"In two days", value:2 * days}, {displayname:"In three days", value:3 * days}, {displayname:"In one week", value:1 * weeks}, {displayname:"In two weeks", value:2 * weeks}, {displayname:"In one month", value:4 * weeks}, {displayname:"In two months", value:8 * weeks}, {displayname:"In three months", value:90 * days}, {displayname:"In six months", value:180 * days}, {displayname:"In one year", value:365 * days}}
property pDefaultDelay : "In one week"

set theDueDate to ""

-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "DNtp" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions

try
	-- Get the selection
	tell application id "DNtp" to set thisSelection to the selection
	
	-- Error handling
	if thisSelection is {} then error localized string "Please select a document or group, the try again."
	if (length of thisSelection) > 1 then error localized string "Please select only one document or group, then try again."
	
	-- Get and format the data we need
	set pLocalizedPrefix to localized string pPrefix
	tell application id "DNtp"
		set thisItem to first item of thisSelection
		set theSummary to (pLocalizedPrefix & ": " & name of thisItem) as string
		set theURL to (reference URL of thisItem) as string
	end tell
	
	-- Let the user choose the reminder list
	set theChosenListName to "Inbox"
	
	-- Let the user choose when to receive the reminder
	-- Convert array into localized arrays
	set theDelayValue to 3600 * 24
	
	
	-- Calculate due date
	if theDelayValue > 0 then
		set theDueDate to (date (date string of (current date))) + theDelayValue
	else if theDelayValue < 0 then
		try
			set theDueDate to (date (text returned of (display dialog (localized string "Enter the due date") & ":" & return & (localized string "Example: 1/1/2017 10:45pm") default answer "")))
		on error
			return
		end try
	end if
	
	-- Add new to do to Reminders
	tell application "Reminders"
		tell list theChosenListName
			--Create new to do
			if theDueDate ≠ "" then
				set theEvent to make reminder with properties {name:theSummary, remind me date:theDueDate, body:theURL}
			else
				set theEvent to make reminder with properties {name:theSummary, body:theURL}
			end if
			show theEvent -- Show new to do item in Reminders so that the user can edit it right away
			activate
		end tell
	end tell
	
on error errMsg
	
	display alert (localized string "Error when adding item to Reminders") message errMsg
	
end try

these 2 script.

The script uses the command
set theRecord to create record with {name:theSubject & “.eml”,…

theRecord points to the item created in Devonthink

Thanks a lot! It works then.