Return value of replicate and duplicate commands

According to the scripting dictionary, replicate and duplicate accept “a record or a list of records” as input.
However, they are said to return only a single record.

  • Is that a just an omission in the documentation, i.e. the commands return a list of records if a list of records is passed in?
  • Or if they only return a single record for a list to replicate/duplicate – which record is that?
  • The documentation is incorrect or misleading: duplicate and replicate do not accept a list of records, despite what the dictionary states.
  • The command returns a single record, which matches what the documentation claims.
  • When given a list, the command fails with error -1701, rather than returning only one record.
  • A workaround is required, iterating over records manually.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set selectedRecords to selection
	if (count of selectedRecords) > 0 then
		set targetGroup to current group -- Explicitly referencing current group
		set duplicatedRecords to {}
		
		repeat with theRecord in selectedRecords
			try
				set newRecord to duplicate record theRecord to targetGroup
				set end of duplicatedRecords to newRecord
			on error errMsg number errNum
				display dialog "Error duplicating: " & name of theRecord & " (" & errNum & "): " & errMsg
			end try
		end repeat
		
		display dialog "Duplicated " & (count of duplicatedRecords) & " records."
	else
		display dialog "Please select at least one record."
	end if
end tell

Both commands support a list of records and return a list in this case, e.g. this works fine over here:

tell application id "DNtp"
	duplicate record (selected records) to current group
end tell

Tested on Intel & M1 and on Ventura/Sonoma.

That’s a limitation of the current script suite based on .scriptSuite & .scriptTerminology files, a future release will use the modern .sdef format instead.

1 Like

This should work for replicants

tell application id "DNtp"
	set replGroup to create location ((location of current group) & "Replicants") in current database
	repeat with r in (selected records)
		replicate record r to replGroup
	end repeat
end tell

No need to use a loop in this case either:

tell application id "DNtp"
	set replGroup to create location ((location of current group) & "Replicants") in current database
	replicate record selected records to replGroup
end tell
1 Like

:blush:
I still have much to learn to make things short

tell application id "DNtp" to replicate record selected records to (create location ((location of current group) & "Replicants") in current database)