On 2008 Oct 6, at 11:21, Peter Kilcoyne wrote:
Hi Folks:
My question is what's the best method to dupe records? I have two
databases, one is the "main" database where using a portal the user
creates and view "parts" of the main job that will live in the
second database. But since a majority of the work we do has been
done last year and only needs minor updates, I want to duplicate
the older "Parts" into the new "Main" with a new job number which
is auto generated via a script when a new job is created.
The idea is the user would search the records for the job they want
to dupe and via a script the would be able to import/dupe all of
the records associated with that job into the new "Main" job with
the updated job numbers. Then they can go about making the minor
informational changes manually
Any ideas?
TIA:
Peter
Here's how I'd do it.
In "Main" create global fields for "Old Record ID" and "New Record
ID". In "Parts" create global fields for "Record Count" and "Step
Number".
In "Main" create a "Dupe" button and attach it to a script called
"Dupe Main and Parts".
Within that script, start by saving the current record ID into "Old
Record ID". Then duplicate the existing "Main" record and save ITS
record ID in "New Record ID".
Next the script turns its attention to "Parts", where it does a Find
for all records where "Main Rec ID" matches "Old Record ID". Fill
"Record Count" with "Get ( FoundCount )" and "Step Number" with "0".
Sort by anything. (Doesn't matter what; the idea is that, in a sorted
list, duplicates get added immediately after the record they're a
dupe OF, while in an unsorted list, they get added to the end of the
list.) Go to 1st record. Start a loop which will end when "Step
Number" equals "Record Count". Duplicate the record, change "Main Rec
ID" to "New Record ID", add 1 to "Step Number", go to next record,
end loop.
Last script step should be to return to "Main", where you will see
your newly created "Main" record and all its associated "Parts"
records displayed in their portal.