Creating record in a group

I am having problems creating a record in the current group of a PDF that I have opened in a new window. The scenario is that I am annotating PDFs by calling upon a modified version of korn’s annotation script. My modified version displays a dialogue box enabling me to select what is the kind of annotation i.e. ‘key information, methodology, summary, references’ and then applies a colour to the annotation (in the PDF) based on keyboard shortcuts that I have assigned. However where the script falls down is that I want the annotation to be saved in the current group of the PDF that I am annotating. Despite specifying the group the group selection dialogue box keeps opening. I am not sure what I am doing wrong here.

--Original Script by Korm

property noDecoration : "\" style=\"text-decoration:none;"
property preferRTF : true


tell application id "DNtp"
	
	try
		
		(*
         Select a single document
      *)
		set thisItem to the first item of (the selection as list)
		if thisItem is {} then error "Please select something"
		
		
		(*
         Get selected citation text
      *)
		--set theCitedText to selected text of think window 1
		--if theCitedText is "" then error "Please select some text"
		
		set theCitedText to the (selected text of think window 1 as string)
		if theCitedText is "" then error "Please select some text"
		
		
		set AppleScript's text item delimiters to "."
		set theName to text items of (the name of thisItem as string)
		set thePrefix to the first item of theName
		
		(*
         Get a note for this clipping
      *)
		set theNote to text returned of (display dialog "Notes for this clipping:" with title "Notes" default answer "[none]")
		
		(*
	Set the Annotation type
	*)
		set the pHighlight to (choose from list {"Methodology", "Key Information", "Summary", "References"} with prompt "Select annotation type:" default items {"Key Information"}) as string
		if the pHighlight is "false" then error number -128
		
		
		(*
         Get a name for the annotation document
      *)
		set theAnnotationName to text returned of (display dialog "Name for this annotation file" with title "Annotation File Name" default answer (""))
		
		(*
         Make a text-search link for this citation
      *)
		if number of words of theCitedText is greater than 5 then
			set maxWords to 5
		else
			set maxWords to number of words of theCitedText
		end if
		set thisWord to 1
		set theCitedTextText to ""
		repeat while thisWord is less than or equal to maxWords
			set theCitedTextText to theCitedTextText & word thisWord of theCitedText
			set thisWord to thisWord + 1
			if thisWord is less than or equal to maxWords then
				set theCitedTextText to theCitedTextText & "%20"
			end if
		end repeat
		set searchCitationLink to " (<a href=\"" & (the reference URL of thisItem as string) & "?search=" & theCitedTextText & noDecoration & "\">" & " Text " & "</a>)"
		
		(*
         Make a path link for this document
      *)
		set thePathLink to " (<a href=\"file://" & the path of thisItem & noDecoration & "\">" & " File " & "</a>)"
		
		(*
         Make a page link for this page if the document is a pdf
      *)
		if the current page of think window 1 ≠ -1 then
			set pageNumber to ((the current page of think window 1) as string)
			-- 20110212 adjust page number to +1 for printing purposes
			set printPageNumber to " (Pg. " & (((the current page of think window 1) + 1) as string) & ")"
			set thePage to "?page=" & pageNumber
			-- set clickHere to "(Click here - page " & pageNumber & ")"
			set clickHere to "| Page " & pageNumber & " link"
		else
			set thePage to ""
			set clickHere to "| Page Link "
			set printPageNumber to "<b><i> (no page - source is not PDF)</i></b>"
		end if
		set theURL to (the reference URL of thisItem as string) & thePage
		set thePageLink to " (<a href=\"" & theURL & noDecoration & "\">" & " Page " & "</a>)"
		
		(*
         Compile all these elements and prepare the annotation
      *)
		set theAnnotation to "<p><b>" & thePrefix & "</b> " & thePageLink & searchCitationLink & thePathLink & "</p>" & "<p><b>" & pHighlight & "</b></p>" & "<p>" & theCitedText & printPageNumber & "</p>" & "<b><i>Notes:</i></b><br>" & "<p>" & theNote & "</p>" & "<p>"
		
		if preferRTF then
			set o_theAnnotation to (do shell script "echo " & quoted form of theAnnotation & " | textutil -format html -convert rtf -stdin -stdout")
		else
			set o_theAnnotation to theAnnotation
		end if
		
		(* Select the group
		*)
		
		set theGroup to the location of thisItem as string
		
		
		(*
         Create the annotation document
      *)
		set theAnnotationDocument to (create record with {URL:theURL, name:theAnnotationName, source:o_theAnnotation, type:rtf}) in theGroup
		
		
	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
	
end tell

(*
		Set highlight colour
		*)

if pHighlight is "Key Information" then
	tell application "System Events"
		keystroke "y" using {control down, command down, option down}
	end tell
else if pHighlight is "Methodology" then
	tell application "System Events"
		keystroke "o" using {control down, command down, option down}
	end tell
else if pHighlight is "Summary" then
	tell application "System Events"
		keystroke "r" using {control down, command down, option down}
	end tell
else if pHighlight is "References" then
	tell application "System Events"
		keystroke "g" using {control down, command down, option down}
	end tell
end if


The correct syntax is


set theGroup to create location "/Yada/yada" in the current database

There is an AppleScript bug in some cases that causes the group selector to open unncessarily. Talk to Apple.

Thanks korm, however the changes don’t work in the script and the group selector keeps appearing. I would presume that there is a bug therefore in Applescript