Script modifies the wrong record

Since several years back I used a (Devonthink script) that I modified. The script creates a new note, with my form of filename and template text. Lately, possibly after installing 3.0.2 the script no longer works correctly.
The scripts create a new file and assigns it the correct filename, but the template text is placed in the record previous to the newly created one.
The script (shortened)
tell application id “DNtp”
try
activate
set myGroup to create location myJournal
set label of every child in myGroup to 0
set root of think window 1 to myGroup
if not (exists child recordName of myGroup) then
set myRecord to create record with {name:recordName, rich text:"", type:markdown, label:0, tags:""} in myGroup
open tab for record myRecord in think window 1
end if

	tell text of think window 1
		set newHeader to "#### " & newHeader & return & return
		make new paragraph at end with data (newHeader)
		set properties of last character to {font:"Georgia", size:18, alignment:left, superscript:0, color:blackcolor}
		set last character to last character
		
	end tell
	hide progress indicator
	
on error errMsg number errNum
	hide progress indicator
	display alert (localized string "An error occured when adding the note. ") & errMsg
end try

end tell

Appreciate all help to solve this
Regards

Here is the script you posted. It is incomplete. Please post the whole script so readers can figure out what’s going on.

tell application id "DNtp"
	try
		activate
		set myGroup to create location myJournal
		set label of every child in myGroup to 0
		set root of think window 1 to myGroup
		if not (exists child recordName of myGroup) then
			set myRecord to create record with {name:recordName, rich text:"", type:markdown, label:0, tags:""} in myGroup
			open tab for record myRecord in think window 1
		end if
		tell text of think window 1
			set newHeader to "#### " & newHeader & return & return
			make new paragraph at end with data (newHeader)
			set properties of last character to {font:"Georgia", size:18, alignment:left, superscript:0, color:blackcolor}
			set last character to last character
			
		end tell
		hide progress indicator
		
	on error errMsg number errNum
		hide progress indicator
		display alert (localized string "An error occured when adding the note. ") & errMsg
	end try
end tell

(Hint, if you want to post a script in the forum, paste the script between markup like this:)

```var
<paste the script here>
```

Thank you for helping me with this, here is the complete script.

property blackcolor : {0, 0, 0}
property myJournal : "/Dagbok/"

set theDate to current date
set theTime to time string of theDate

set recordName to theDate as string
set newHeader to theTime


tell application id "DNtp"
	try
		activate
		set myGroup to create location myJournal
		set label of every child in myGroup to 0
		set root of think window 1 to myGroup
		if not (exists child recordName of myGroup) then
			set myRecord to create record with {name:recordName, rich text:"", type:markdown, label:0, tags:""} in myGroup
			open tab for record myRecord in think window 1
		end if
		
		tell text of think window 1
			set newHeader to "#### " & newHeader & return & return
			make new paragraph at end with data (newHeader)
			set properties of last character to {font:"Georgia", size:18, alignment:left, superscript:0, color:blackcolor}
			set last character to last character
			
		end tell
		hide progress indicator
		
	on error errMsg number errNum
		hide progress indicator
		display alert (localized string "An error occured when adding the note. ") & errMsg
	end try
	
end tell

I’m not seeing any errors. This is what I get when the script is run – is that what you expect:

and then this the next time the script is run

Yes, that’s what expected.
In my system, the markdown note is created properly but the text “#### time” is added to the end of the previous record.
As I noted earlier this started a couple of days ago. Could be a macOS thing (using 10.15.2-beta (19C46a)).
First I thought it could be a function of my diary being a bit large, but creating a new one in another database, I still get the same behavior.
Will continue to look for clues.
Thank you for verifying result
Regards
Gunnar

1 Like

Problem solved!
Found that I activated two different scripts with same shortcut from Devonthink.
(Why this has not surfaced earlier is beyond me)
Anyhow, everything is now back to normal.