1 Reply Latest reply on Apr 13, 2015 1:28 PM by philmodjunk

    Automatically populate a field in a new table

    KevinMcCowen

      Title

      Automatically populate a field in a new table

      Post

      I'm trying to create a database that allows tests to be assigned to a single sample ID. Right now the database is set up so that a sample number is automatically assigned in one table, in which information about the sample is input. Then a button is used to open a new table in which sample tests are put in for each sample ID. Right now it is set up so when the new form opens I have to input the sample ID, then assign the test. If I have 10 tests I have to do this 10 times.

      What I want to do is build a table that allows me to click a button, on the initial sample entry, and the sample ID will autopopulate the field in the new table, where all of the tests can be entered at once.

      Thanks for your help.

       

        • 1. Re: Automatically populate a field in a new table
          philmodjunk

          Samples---<Tests
          Samples::__pkSampleID = Tests::_fkSampleID

          A portal to tests on a Samples layout might eliminate the need for a new layout, window and script as entering data directly in the portal can generate records in tests that are automatically linked to the current Samples record.

          But you can also set it up this way:

          In your script to open the new window, include a set variable step that holds the pk of your current samples record:

          Set Variable [$$SampleID ; value: Samples::__pkSampleID ]
          New window...
          and so forth.

          Then define _fkSampleID to include this auto-enter calculation:

          $$SampleID

          and each new record that you create in your newly opened window for adding Tests records will automatically enter the value of this global variable and thus automatically link to the current record in Samples.

          And it may be better to use OnRecordLoad on your Samples layout to capture the pk in the $$SampleID variable.