5 Replies Latest reply on May 21, 2010 2:46 AM by fitch

    Reading/Writing records to a table in script mode



      Reading/Writing records to a table in script mode


      I'm new to Filemaker scripting.The supplied documentation leaves somethng to be desired :-)

      I've got me a nice script made for processing data file containing info about members of a club. Works great, fine.


      At the end of my script I want to "save" a sum total. Is it possible to create (= add) a new record in a table during/at the end of a script?

      It's possible that the record already exists (the script may be run more often), so I need to be able to save to a:


      1. existing record (question: how do I identify a specific occurence in a table, then update and save (commit)?)

      2. non existing record (question: how do I create and save a new record to a table?)


      It's probably basic stuff but the documentation supplied fails to enlighten.

      Thanks again for the leg-up :-)

        • 1. Re: Reading/Writing records to a table in script mode

          You can create or update records through relationships, or you can go to a layout based on the correct table, find the record, and update, or if none found create a new record. If needed you can do this in a new window.


          Are you looking at the printed docs? IMO, the online documentation is pretty good.

          • 2. Re: Reading/Writing records to a table in script mode

            Can you explain why you are trying to do this? A more full detailed explanation wil  help with better advice.

            • 3. Re: Reading/Writing records to a table in script mode

              I'm sorry, I haven't been clear enough.

              My database contains information on members of an investment club. Each member has contributed a certain (mostly different) amount to the 'kitty', sometimes in different installments. Every Quarter the profit / loss of the total investment is distributed across the club members.


              The script I'm making now is what I call  the quarterly batch run. Based on the input parameters (year and quarter), I run through the member contributions (possibly more contributions per member and a contribution can have been made during the quarter and therefore not fully liable for a profit/loss adjustment). The basic processing is working fine (also thanks to your help) but I want to "save" the sum total of the adjustments in a table which essentially is no more than a record with year, quarter and sum-total fields. The first time I process I'll need to create the record in the table.The existance of the record is also the registration of the fact that the quatrerly profit/loss has been processed. But it''s possible I'll need to run the script more often for the same quarter so I'll need to check if the record already exists.

              I'm only getting familiar with Filemaker, but I have extensive experience with Cobol, CICS, etc. (yeah, that generation!!). I am therefore used to retrieving records on key and field values. If the record does not exist, then you 'write' the record with the appropriate field values. I guess I'm just looking for the equivalent statements in Filemaker script language. Maybe my "index sequential" past prohibits me from thinking in a Filemaker way.


              Anyway, I hope this is sufficient background. Cheers, Mike

              • 4. Re: Reading/Writing records to a table in script mode

                Thanks Tom.

                As I said I'm still getting failiar with Filemaker. I have a Cobol/index sequential past and heve taken up programming recently. I understand your solution but I have a question: is it possible to go to a layout and process as you suggest without the layout appearing on the screen? or does a go to a layout automatically put it on the screen.

                Also, how exactly do you create a record in a table in the scripting language. Is that the commit statement?


                Thanks again, Mike

                • 5. Re: Reading/Writing records to a table in script mode

                  You can specify negative numbers (or very large numbers) in the window's Top and Left options to make the window draw off-screen.


                  One way to create a record is the script step New Record/Request. (If you're in Find mode it makes a new find request rather than a new record.)


                  Another possibility is to create a relationship and select the "allow creation of records" option in the relationship. You can then make a portal on the parent layout. In your script, you can go to the last row of the portal and use Set Field to push data into the related field, which will create the related child record.


                  There are also fancier techniques that can create the child records without a portal.