2 Replies Latest reply on Aug 17, 2013 1:36 AM by JeromeSimons

    Script that inserts new records and pastes values from origin table, copy/paste does not work.

    JeromeSimons

      Title

      Script that inserts new records and pastes values from origin table, copy/paste does not work.

      Post

           Dear All,

           I wish to create a script that takes records from columns/fields and copies them into another table. I made the beginner's mistake of creating a few columns for individual grant disbursements which would be better recorded in table rows. Now, having entered the data already, I wish to write a script that first finds the appropriate rows (i.e. disbursements that are not empty etc.) and then makes a new record in a related table copying the grant id (which is the same for each disbursement) into the table and creating a new record for each disbursement value. My script is attached as a screenshot.

           I am basically wondering about the potency of copy/paste after having created a new record using the relationship and SetField[]. So, I am wondering about how to paste values into the row that ensues after having created the record. The records get created but for some reason, the copy/paste does not work and the target field records stay blank.

           I would greatly appreciate your help.

           Kind regards,

           Jerome

            

      script.jpg

        • 1. Re: Script that inserts new records and pastes values from origin table, copy/paste does not work.
          philmodjunk

               Copy and paste should never be used except for very limited purposes where there is no alternative. Copy overwrites any data that the current user may have already copied and this confuses and irritates them when your script replaces the data that they copied with data copied by the script.

               There is a better alternative: Set Variable (copy) and Set Field ( paste).

               But the reason that your script doesn't work is that it should be changing back and forth between a layout based on the table from which your are copying data and a layout based on the table where you want to create new records.

               Here's a generalized outline of the needed script, subsitutute your name for mine and add as many pairs of set variable, set field steps as you need:

               Freeze Window
               Perform find[...
               Loop
                  Set Variable [$ID ; value: OriginalTable::PrimaryKey ]
                  Set Variable [$Data ; value: OriginalTable::DataField ]
                  Go To Layout ["New Table" (NewTable) ]
                  New Record/Request
                  Set Field [ NewTable::ForeignKey ; $ID ]
                  Set Field [NewTable::DataField ; $Data ]
                  Go to Layout [original table]
                  Go to Record/Request/Page [First ; exit after last ]
               End Loop

               The above script assumes that you have set up this relationship:

               OriginalTable::PrimaryKey = NewTable::ForeignKey

               Where PrimaryKey is either an auto-entered serial number field and Foreing key is a number field or PrimaryKey autoenters Get ( UUID ) and ForeignKey is then a text field.

          • 2. Re: Script that inserts new records and pastes values from origin table, copy/paste does not work.
            JeromeSimons

                 Thank you so much for your kind advice! This worked out very well.