5 Replies Latest reply on Dec 19, 2012 8:19 AM by comment

    creating additional records from table 1 into table 2

    fmk4

      Hi,

       

      Is it possible to create additional records from table 1 (layout A) into table 2 using scripts?

       

      If a record is created in table 1 using controls on layout A, 2 or more records is created on table 2, each of these records has different information generated from the record in layout A.

       

      Example,

       

      If I input A,B,C,D in layout A, I want to generate 4 records in table 2 from layout A, ie record 1 =A, record 2=B, record 3=C, record 4=D.

       

      I tried using new record, but it only trigger a new record in layout A.

        • 1. Re: creating additional records from table 1 into table 2
          comment

          fmk4 wrote:

           

          If I input A,B,C,D in layout A, I want to generate 4 records in table 2

           

          What would be the purpose of duplicating the data like that?

          • 2. Re: creating additional records from table 1 into table 2
            fmk4

            Hi,

             

            Its for permutation entry.

             

            If user enters ABC in layout A, I need to create the corresponding entries with permutation in table 2.

             

            Table 1

            ABC

             

            Table 2

            ABC,

            ACB,

            CAB,

            BAC,

            ...etc

            • 3. Re: creating additional records from table 1 into table 2
              comment

              Well, you could certainly script the process, if you wanted. Whether that's a good way to proceed is another question. Suppose user edits the original entry: you would then need to delete all related records and create a new set, right? You didn't say how the related records will be used - perhaps deleting them would create orphans further down the line.

               

              IOW, abstract questions do not yield the best answers. It's much better, IMHO, to describe the real situation.

              • 4. Re: creating additional records from table 1 into table 2
                fmk4

                How do I script it such that with the input in layout A (table 1), I can create multiple records in table 2?

                 

                I tried using new record, but it only creates a new record in table 1, and not table 2.

                 

                There is no need for consideration for orphan records, as once the records are permutated, its stays there for both table 1 and table 2. There is no delete for both the records in both table.

                • 5. Re: creating additional records from table 1 into table 2
                  comment

                  The New Record command (or script step) creates a new record in the current table - that is the table to which the current layout belongs. In order to create a new record in another table, you need to switch to another layout. Using your first example, the script could look something like:

                   

                  Set Variable [ $parentID ; Parent::ParentID ]

                  Set Variable [ $values ; Parent::Input ]

                  Go to Layout [ Child ]

                  Loop

                  Set Variable [ $i ; $i + 1 ]

                  Exit Loop If [ $i > ValueCount ( $values) ]

                  New Record

                  Set Field [ Child::ParentID ; $parentID ]

                  Set Field [ Child::Value ; GetValue ( $values ; $i ) ]

                  End Loop

                  Go to Layout [ Original layout ]

                   

                  This is assuming user will enter a return-separated list of values into the Input field of the Parent table.