4 Replies Latest reply on Aug 21, 2013 10:24 AM by davehob

    Button to insert more than one line in other table



      Anybody know a script to insert some fields information in another table in filemaker.

      as a exemple, I create a button and set a trigger, when I click on the button the information of the field create a new line in other table and go there, the field is clean to inser other information and create a new line with the new information....



        • 1. Re: Button to insert more than one line in other table

          Not sure I've understood you correctly, but how about:


          Go to Layout [name of layout based on the "other table"]

          New Record/Request


          (Note - you mention "a trigger", but, from your description, this would be a simple "Perform script" button, not a triggered script as such.)



          1 of 1 people found this helpful
          • 2. Re: Button to insert more than one line in other table

            Dave's method will work quite well if the new records you want to create don't have anything to do with the record you're currently looking at.


            If the table where you want to create one or more new records is related to the current record, you may be better served by creating a portal on the current layout with "Allow creation of records" checked on the relationship in the Relationships Graph. The script would then look something like this:


            Go to Field [ {related field} ]

            Go to Portal Row [ Last ]

            Set Field [ {related field} ; {new value} ]

            Set Field [ {related field} ; {new value} ]

            (repeat for all new fields)


            You can then repeat the process for each new related record you want to create.


            The advantages to this method include:


            1) Automatically updating the key in the related table.

            2) Taking advantage of FileMaker's transactional model so you can revert all the changes if something goes wrong.





            • 3. Re: Button to insert more than one line in other table

              If you don't like the idea of putting a portal on your layout, you can achieve the same effect by creating a new field in the table your layout is based on (let's say "id_CREATE"), and a dedicated TO relating BaseTable::id_CREATE = OtherTable::id (where "id" is OtherTable's primary key), with creation of related records turned on on the OtherTable side. Then I'd write a script something like this:


              Set Field [BaseTable::id_CREATE; Get ( UUID ) // will become id of first new record in OtherTable]

              Set Field [OtherTable::field1; "value1"]

              Set Field [OtherTable::field2; "value2"]

              # The following Set Field step will sever the relationship with the first created record, but not commit the record

              Set Field [BaseTable::id_CREATE; Get ( UUID ) // becomes id of second new record in OtherTable]

              Set Field [OtherTable::field1; "value1"]

              Set Field [OtherTable::field2; "value2"]

              Set Field [BaseTable::id_CREATE; "" // sever connection to second new OtherTable record]

              Set Error Capture [On]

              Commit Record/Request [Perform without dialog]

              Set Variable [$error; Get ( LastError )]

              Set Error Capture [Off]


              With this method, you don't have to switch layouts (fast), the operation is transactional (good data integrity), and you don't have to put anything on your layout. On the downside, you can't go back and edit the earlier-created records without committing the transaction first as you can with a portal.

              • 4. Re: Button to insert more than one line in other table

                Really interesting.  This looks like a strong argument in favour of using UUIDs for keys, i.e. that you can use the "create record without leaving home" technique for multiple record creation.  Do you generally favour UUIDs for other reasons?  (I have to admit to using keys which are semi-meaningful, with a table mnemonic followed by a serial no., e.g. "PPL000015", but I know that's not best practice.)