Import records, when importing records from a file that is already open, imports the current found set of the source table. All you need to do is create a script that sets up the correct found set of records before importing.
Since you can see the records in a portal. Go To Related Records would appear to be a good option for this. Here's a rough outline of the script:
- Use an If statement with IsEmpty ( Portaltable::IDfield ) to make sure that there is at least one record visible in the portal.
- If there is, use Go To Related records, specifying Show only related records for the current record and also specifiying a layout based on the portal table.
- Then use Import Records to copy the records over to the target table.
Import records can result in large scale changes and/or additions to your database so make a back up copy before testing your script. There's a known bug in import records that can have a catastrophic effect on your data if your import does not use the matching records option and you make changes to a table design: Data loss bug : Spontaneous and erroneous import matching of new fields in specified imports !
Scripts that use Go To Related Records without checking and trapping for situations where there are no related records to go to can also result in major, unexpected results for your database: See filemaker help if you are using filemaker 11. For other versions or to read more about go to related records, see: The Complete Go To Related Record
thanks so much for the help, Phil.. i was fiddling with this all last night and had originally tried it this way, but i must be missing something because its still importing all the records. ive attached a screenshot. bottom right is my script, top left is what opens when i use the go to related records and then constrain the found set to find the related records that meet my criteria.
You can see in the background (bottom is my portal to DB2Table, top is my DB1Table portal) that my script is still importing all of the records (there are 3 test records in total in DB2Table, only 2 are visible because the other is unrelated.) in DB2Table. Could you please look over my script and tell me what I'm doing wrong?
Also, ty for the heads up on the errors. I incorporated the isempty if statement as you suggested.
Please read the link on Go To Related records or look it up in filemaker help if you have filemaker 11.
You script should be something like this:
If [ not IsEmpty ( Incoming Proposals::Proposal No) /* check for the existance of related records */ ]
Go To Related Records ( Show only related records; From table: "incoming proposals"; Using layout: "IncomingProposals"
//Don't use the new window option, you don't need it and it may interfere with having the correct found set for your import records
Constrain Found Set [Restore]
Go To Layout [original layout]
On a design note, importing records back and forth between tables can be risky as one of the links above documents. It's very possible that the effect you are after here could be achieved without importing records from one table to the other. You might, for example be able to manage your proposal records simply by adding a status field and managing what records are pulled up via finds and/or relationships that include the status field and also with filtered portals.