Jump to content
The ORIGINAL FileMaker Community - Forum - Online Business Apps & Software Forum
boywonder

Duplicate all records in current found set

Recommended Posts

boywonder

I have a series of records that need to be duplicated in a given found set. I've written a script to duplicate a series, but it keeps pausing after duplicating the first record. I know I'm missing something obvious:

 

Loop

Go to Record Request page first

duplicate record request/page

go to record request page next, exit after last

End Loop

Share this post


Link to post
Share on other sites
dj

You could also use this sequence:

 

Make Found set of interest

Export Records to Buffer (any type of file FM can handle)

Import Records from Buffer

 

Dj

Share this post


Link to post
Share on other sites
macca
Originally posted by boywonder:

[qb]Loop

Go to Record Request page first

duplicate record request/page

go to record request page next, exit after last

End Loop[/qb]

the go to first record should also be put BEFORE the start of the loop.

 

i.e.

Go to record [first]

Loop

...do stuff

go to record[next, exit after last]

end loop

Share this post


Link to post
Share on other sites
boywonder

New it was simple, thank you

 

go to record request/page (first)

Loop

duplicate record/request

go to record/request/page (next)

duplicate record/request

go to record/request/page(exit after last, nest)

end loop

 

** had to add the second command for it to not stop after the first duplicate **

 

beauty

Share this post


Link to post
Share on other sites
amanco999

How can I use this to duplicate a portal or multiple rows into another portal? 

thanks

Share this post


Link to post
Share on other sites
AHunter3

First go to related records [show only related] for each portal whose recs you want to duplicate.  (Test first to verify that there are any to go to). 

If you're copying them to a second portal related to the same local record:  is the second portal a portal to the same native table, or a different table?  If it's the same table via a different relationship, you'll be looping and duping and changing the relevant foreign key of the dupes so as to make the duplicates show up in the 2nd portal (and not in the 1st portal).  If it's an entirely different table you need to harvest the field values (for example setting $Variables) or else snag unique identifiers for the recs you're making duplicates of — then head off to the other table and make brand-new records and either write out the values you stores in $Variables or else use a relationship to the other table anchored in the unique ID you snagged to set each field in this table to the corresponding field value in the original table.

----

The original advice up above for duplicating a found set of records is midleading and should be modified to behave like this, though:

 

Set Variable [$RecNumber; 1]

Loop

Exit Loop If [ GetAsNumber ($RecNumber) > Get (FoundCount)]

Go to Record [$RecNumber, no dialog]

Duplicate

... do stuff to the duplicated rec as need be

Omit Record/Request

Set Variable [$RecNumber; $RecNumber+1]

End Loop

 

 

 

Share this post


Link to post
Share on other sites
amanco999

Thank you AHunter for the explanation, 

I tried the above, but it keeps looping creating unlimited records. I am not sure what I did wrong. 

To clarify, I am copying patients medications from table "Pre Admission Medications" to another table "Discharged Medications" for the same encounter or admission ID to the hospital. 

Images attached to copy all the rows with data starting with:

# | Medication | Form | Dose | Strength | Frequency | ....... etc

I am sorry im new to filemaker. Please let me know if you need more information.

Thanks again

01_Premed.PNG

02_dischargedMeds.PNG

MedicationsTables.PNG

Script.PNG

Share this post


Link to post
Share on other sites
AHunter3

 

Step 1, Go to Related Record, should match current record only, NOT the current found set.  

Step 2, you're setting the variable $Medication to a field value.  That's wrong.  Set it to the number 1.

Step 5, in side your loop, is entirely wrong.  It's supposed to be Go to Record.  Not Go to Related Record.  And the record to go to should be by calculated value, $Medication

Step 7:  You're setting a field (tbl_DisachargeMedications::DischargeMedication), but you're not setting it to anything.  What are you trying to set it to?  How do you know what value it should be set to?

 

Share this post


Link to post
Share on other sites
amanco999
Posted (edited)

Thank you Ahunter,

I corrected the mistakes

Step 5, just to confirm there is Go to Record/Request/Page, I can't find Go to Record only, correct?

Step 7, I just need to duplicate the data into the second table, not sure honestly if I need to use "Set field" or another command. 

I did set field from the 1st table to the second one, but it is still not working.

 

 

 

Script2.PNG

Edited by amanco999
Corrected Set Variable [$Medication; $Medication+1]

Share this post


Link to post
Share on other sites
AHunter3

See where I wrote this in my first modern-era post to this thread?:

 If it's an entirely different table you need to harvest the field values (for example setting $Variables) or else snag unique identifiers for the recs you're making duplicates of — then head off to the other table and make brand-new records and either write out the values you stores in $Variables or else use a relationship to the other table anchored in the unique ID you snagged to set each field in this table to the corresponding field value in the original table.

 

That's your situation.  So you DO NOT want to duplicate your portal records.  Because you want copies of those record to exist, instead, in an entirely different table.  Duplicating them within tba_PreMedications just gives you a second identical record in the tbl_PreMedications table and that's not where you want them.

I should have been more clear about that.  And in my later post where I said the original (old) instructions were not accurate, you followed those thinking they were applicable to your situation.  But they aren't.

 

It's like if you were sending out the same email to a second person you could highlight it and select "Resend" and then change the address, essentially duplicating the existing email and modifying it for your purposes; but if you want to upload a file to someone's web site, duplicating an email won't hel[p you in the slightest.

 

What you want to do INSTEAD is loop through the portal records in tbl_PreMedications and NOT duplicate them but instead record the values that they have in the various fields, like Strength and Dose and Form and so on.  Then you scurry over to the world of tbl_DischargeMedications and you create NEW records, anchored by the same pk_PatientID value that anchors all of the portal records in either portal, and then you set Strength in that record to the Strength value that you had in the PreMedications record.

With me so far?  Ask any questions about things you're unsure of before going on.

-------

There are two pretty obvious mechanisms for "harvesting" the values in PreMedications so as to have them at your fingertips to write out to DischargeMedications.

 

Method A:  Using $Variables, create a stack of all the values of Strength and all the values of Dose and all the values of Form for all the portal records in the PreMedications portal.  At the end of the loop, you'd have the variable $Form containing "Tab" then a hard return then "Cap" then a hard return then "SOLN" and so on; and the variable $Dose would contain "50" then a hard return then "100" then a hard return then "200 and so on.  Etcetera for ALL of the fields that you want to populate in the records you're putting in the other portal.  Then you go over to a layout native to DischargeMedications and you start a new loop, this time creating new records, and you stick the PatientID (which you also saved into a variable) into the fk_PatientID field and for the first record you put the virst VALUE of $Form into tbl_DischargeMedications::Form and so on:

 

Set Variable [$RecNumber; 1]

Loop

Exit Loop If [GetAsNumbger ($RecNumber) > ValueCount ($Form)]

New Record/Request

Set Field [tbl_DischargeMedications::fk_PatientID; $SavedPatientID]

Set Field [tbl_DischargeMedications::Form; GetValue ($Form; $RecNumber]

Set Field [tbl_DischargeMedications::Dose; GetValue ($Dose; $RecNumber]

etc

Set Variable [$RecNumber; $RecNumber+1]

End Loop

 

 

Method B:  

Make a new relationship between tbl_DischargeMedications and tbl_PreMedications.  You'll need a new table occurrence of tbl_PreMedications to be inserted on your graph, let's call it "SourcePreMedication".  You'll need a new number field in DischargeMedications let's call it Source__PreMedicationID.  The relationship is 

tbl_DischargeMedications::Source_PreMedicationID = tbl_PreMedications::__pkPreMedicationID

 

Now instead of "harvesting" values for Form and Dose and Strength and so on, all into their respective $Variables, all you have to harvest is the __pkPreMedicationID value, putting a hard return after each one before putting the next, so you have a bunch of serial numbers in that variable separated by hard returns.

Then after you've harvested all those you go to DischargeMedications just like in Method A but in your loop this time you make a new record, set fk_PatientID same as you did before, set the new field Source_PreMedicationID to the value of __pkPreMedicationID that you stuck there; then you can look "over your shoulder" at Source_Premedications to fill in all the other fields through the new relationship:

 

 

Set Variable [$RecNumber; 1]

Loop

Exit Loop If [GetAsNumbger ($RecNumber) > ValueCount ($SourcePreMedIDs)]

New Record/Request

Set Field [tbl_DischargeMedications::fk_PatientID; $SavedPatientID]

Set Field [tbl_DischargeMedications::Source_PreMedicationID; GetValue ($SourcePreMedIDs; $RecNumber]

Set Field [tbl_DischargeMedications::Form; Source_PreMedications::Form]

Set Field [tbl_DischargeMedications::Dose; Source_PreMedications::Dose]

etc

Set Variable [$RecNumber; $RecNumber+1]

End Loop

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use