Easiest method IMO is to use FileMaker's built-in import facilities.
Write a script to:
- store the distributionID in a variable
- go to a Customer layout and find all active customers
- go to a table occurrence of Distribution
- define an Import Records step with the table occurrence of the Customer layout where you performed the Find as the source, and this distribution table occurrence as the target.*
- use Replace Field Contents to set the distribution foreign key for the newly imported records to your $var
* you need to create a External Data Source for that to work. Just select the veery same file you're working in.
You could also collect the IDs of all active customers using ExecuteSQL(), or, if neither method appeals to you, do this:
Set Variable [ $listOfClientID ; List ( Clients::id ) ]
Set Variable [ $listOfClientStatus ; List ( Client::status ) ]
Set Variable [ $clientCount ; ValueCount ( $listOfClientID ) ]
Exit Loop if [ Let ( $i = $i + 1 ; $i > $clientCount ) ]
If [ GetValue ( $listOfClientStatus ; $i ) = "Active" ]
Set Field [ Distribution::id_customer ; GetValue ( $listOfClientID ; $i ) ]
Bits and pieces seem to be missing here. As near as I can tell, you have these relationships:
Clientes----<Items>-----Distribucions (---< means "one to many")
Clientes::ID = Items::ClientID
Distribucions::ID = Items::DistributionsID
But then you mention a table (maybe table occurrence) named DstLine but don't say how it is used or how it relates to the other table occurrences.
It is not clear whether you want your script to create a new record in Distributions or in Clientes or perhaps another table. As written, it creates new records in Distributions.
So what exactly are you trying to accomplish with this script?
What i am trying to do is in Distribuition Layout, (where i define the date and the content to Customers),
i want to have a portal of clientes "Actives" in Left bottom and a portal of DstLines right bottom to receive the chosen clients from left portal.
the choice can be one-by-one or with a button to select all.
i hope you understand the idea.
Don't understand. DstLines could be a different table or an occurrence of clientes or ???
And how does the user select clients from the portal if active clients? Do you want to click a record in the left hand portal to see a record appear on the right, have the user click to select a group of records then click a button to see a group of records on the right?
DstLines is not Occurrence, is normal table. in left hand portal i have a filter portal record set all "active".
in the right hand portal is DstLine, will be populated by script in the button "move all".
please take a look this to scratch.
the script to insert one-by-one is done. what if there is more than 100 records?
how can i send the all client_ID into DstLines table?
I do this UI usually by allowing the user to collect whatever entries they want in a global $$var (and provide feedback via Conditional Formatting), then “move” them as a batch (however large that batch may be).
This goes together with convenience functions à la "Select all" (empty $$var and set it to List ( Client_active::id )) or "Select none" (just empty the $$var) from which point one can fine-tune the selection.
Once the user clicks “Move”, and the $$var isn't empty, you can use one of the methods described in an earlier post.
“Remove all” would mean: delete all related records for this Distribution record.
1 of 1 people found this helpful
To create new records in the DistLines table this way, you would not do it by creating new records in Distributions--which is what your current record does. To use New Record/Request to create a new record in a specific table requires that your script use go to layout to go to a layout based on an occurrence of that table.
There is also another method that you could use that does not require changing layouts: MagicKey. You can web search this term to find some excellent articles on how to set this up and thus not need to change layouts or open an extra window (as is often done with the changing layout method).
The basic script for both methods requires:
- Collecting a list of all clients from the first portal. If it is unfiltered, the List function may be used to set a variable to the list of client ID's.
- Loop through the list creating new related records.
If you use new record/request to create the new records, you need to change layouts between steps 1 and 2 to set the context on the correct table.