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
That’s a limitation of the current script suite based on .scriptSuite & .scriptTerminology files, a future release will use the modern .sdef format instead.
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
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