1 Reply Latest reply on Aug 18, 2015 3:15 PM by philmodjunk

    Script to add records to a related table ..?



      Script to add records to a related table ..?


      I have two tables, SampleInfo and ExperimentalInfo, linked by the common Field SampleID.
      When a users adds a new record into the SampleInfo table, I'd like my database to automatically add a new record in the related ExperimentalInfo table.  Ideally, I'd use a button on the former table, which when clicked runs a script that:
      a) counts the number of records in the SampleInfo table
      b) counts the number of records in the ExperimentalInfo table
      c) if there are more records in SampleInfo, add a record to the ExperimentalInfo table
      d) repeats from step 1 until both tables have an equal number of records
      I've tried running a few scripts with the above in mind, but I'm a little new to all this and various commands I'm familiar with can't make this happen.

      Might anyone be able to point me in the right direction?

        • 1. Re: Script to add records to a related table ..?

          Why would there always be exactly one experimentalInfo record for every sampleInfo record?

          Why to you need to create the added ExperimentalInfo record at the same time that you add a SampleInfo record?

          If you enable "allow creation of records via this relationship" for experimentalInfo you can create the experimentalInfo record the first time that you enter data into  a field from ExperimentalInfo on your SampleInfo layout.

          And the script as you describe it would not work so simply as you would not simply create the same number of records in both tables, but you also have to have each ExperimentalInfo record linked to a different SampleInfo record.