|
|
duplicating record with children
Hi, I found the need to duplicate a record together with all its child
records from a related table (the classic situation of creating a
similar set of records).
My first idea (also confirmed by a newsgroup search) was to use some
kind of loop to duplicate the children. But there are some details that
I don't quite understand.
First, I duplicate the parent record, and store the ID of the new
record in a global field. Then how do I go back to the original
(parent) record? Is it always the "previous" one?
Then how do I loop through the child records? I've seen suggestions
like:
Go to Related Record
Go to record [First]
Loop
Exit loop if [status(currentfoundcount) = 0]
Duplicate Record
Set Field [ParentID; Global]
Omit Record
Go to Record [First]
Omit Record
End Loop
Why is it necessary to omit records and go to the first one every time?
When I duplicate a record, is it automatically added to the found set?
Is it added immediately after the current one? Isn't it just enough to
duplicate and go to the next one, and exit after last?
I hope somebody can shed some light on these things.
Thanks
Adrian
|
|
0
|
|
|
|
Reply
|
aditsu (30)
|
5/23/2005 11:14:29 AM |
|
Does anybody know the answer to this?
Adrian
|
|
0
|
|
|
|
Reply
|
aditsu
|
5/24/2005 3:41:25 PM
|
|
<aditsu@gmail.com> wrote:
> Then how do I loop through the child records? I've seen suggestions
> like:
>
> Go to Related Record
> Go to record [First]
> Loop
> Exit loop if [status(currentfoundcount) = 0]
> Duplicate Record
> Set Field [ParentID; Global]
> Omit Record
> Go to Record [First]
> Omit Record
> End Loop
>
> Why is it necessary to omit records and go to the first one every time?
> When I duplicate a record, is it automatically added to the found set?
> Is it added immediately after the current one? Isn't it just enough to
> duplicate and go to the next one, and exit after last?
If you have Developer, you can turn on Script Debugging and follow this
process.
Where a duplicated record is added to the found set depends on the sort
order of the set. A sorted set will add a record immediately after the
current one. An unsorted set will add a record at the end. Unfortunately
for this process, once the first record is added (duplicated) the set
becomes "Semi-sorted" and where the record is added becomes somewhat
unpredictable. I bet some of the duplication routines you've found
specifically Unsort records before they start, for this reason.
In addition, when you Duplicate a record, you are ON the duplicated
record. That's your focus. How do you ensure that you return to the
next record in the sequence, but don't duplicate the wrong record?
The Omitting in the script above ensures that you're duplicating records
only once. Trying to flow through without omitting means you'd be
duplicating already duplicated records and you'd end in an infinite
loop.
Lynn Allen
--
Allen & Allen Semiotics www.semiotics.com
FSA Associate Filemaker Design & Consulting
|
|
0
|
|
|
|
Reply
|
lynn
|
5/24/2005 4:51:56 PM
|
|
Lynn allen wrote:
> If you have Developer, you can turn on Script Debugging and follow
this
> process.
I have it, but I found the debugging process quite troublesome and
inflexible.
Anyway, I'll debug after I have an idea how to do the duplication
right.
> Where a duplicated record is added to the found set depends on the
sort
> order of the set. [...]
Then I'd rather not count on that at all. But how to go to the children
of the original record after duplicating it?
> I bet some of the duplication routines you've found
> specifically Unsort records before they start, for this reason.
I don't think I've seen that. Is there any other way?
I hate it how I have to find all kinds of workarounds to do something
non-trivial in FM.
> In addition, when you Duplicate a record, you are ON the duplicated
> record. That's your focus. How do you ensure that you return to the
> next record in the sequence, but don't duplicate the wrong record?
Assuming it is right after the original record, going to the next one
will advance to the next original record in the set. But I see that I
can't make that assumption.
Well, I'll do the ommitting; I'm just concerned about the question
above (how to go to the children of the original record after
duplicating it?)
Thanks
Adrian
|
|
0
|
|
|
|
Reply
|
aditsu
|
5/24/2005 6:26:35 PM
|
|
<aditsu@gmail.com> wrote:
> Well, I'll do the ommitting; I'm just concerned about the question
> above (how to go to the children of the original record after
> duplicating it?)
Generally the steps to take are:
1. Freeze Window. That will keep all sorts of flashing about hidden.
2. Go to Related Records of the parent record BEFORE duplication. This
isolates the set in the child table, and will remain until you get
there.
3. Duplicate the parent record and commit the record. Capture the ID of
the new record into a global.
4. Transfer focus to the child table using a go to Layout. The found set
of related records to the original parent will be there.
5. Run the duplication loop, setting the new ID value from the global
into each new record.
6. Return to the new parent record by closing the window used for the
duplication loop. Refresh the parent window, and you'll see the new
child records appear in the portal.
Lynn Allen
--
Allen & Allen Semiotics www.semiotics.com
FSA Associate Filemaker Design & Consulting
|
|
0
|
|
|
|
Reply
|
lynn
|
5/24/2005 9:09:30 PM
|
|
Thank you very much, I succeeded :)
It's a bit strange how FM works with found sets, different layouts and
related records. I'll try to learn and get used to it.
My script is actually more complicated because I'm duplicating records
in several tables (two levels of child records, and some 1:1
relationships) but I just applied the same ideas and it worked.
Thanks
Adrian
|
|
0
|
|
|
|
Reply
|
aditsu
|
5/25/2005 6:26:59 AM
|
|
|
5 Replies
289 Views
(page loaded in 0.051 seconds)
|
|
|
|
|
|
|
|
|