4 Replies Latest reply on Jun 3, 2009 2:30 PM by ekm12

    script to insert rows for subset of data



      script to insert rows for subset of data


      Hello to all...


      I am looking to create a script (initiated with a button) that will insert a new row of data for a subset of data from another table.


      I have a subset of students records and need to create a log for each student.  When I create the records manually using the layouts everything works well, but as a batch/script it creates a new student record instead of the new log.


      Any assistance would be greatly appreciated... thanks 

        • 1. Re: script to insert rows for subset of data

          Your layout design can affect what script, if any, will work best for you.


          Do you have the log records displayed in a portal? Is the relationship that links your portal's Table relationship set up with the "Allow creation of related recordes via this relationship" enabled?


          If this is the case, you can add related data in your log table simply by entering data in the last row of your portal.


          In a script:


          Go To Portal Row [last]

          set field[PortalTable::field, /*specify an expression here */]


          You'd put as many set field steps as you need to enter your data with whatever values/expressions are needed to create your related record.

          • 2. Re: script to insert rows for subset of data

            This is not working for me, I am using Script Debugger to step through the script:


            <!-- StartFragment -->

            Perform script [“Find Walden Students”]


            Go To Record/Request/Page [First]


                     Goto Portal Row [Last]

                     SetField [WS Log Table::StudentID; StudentDB::StudentID]


                     Goto Record/Request/Page [Next; Exit after last]

            End Loop


            In this scenario, the script creates a new “student” record…

                     (31 more new students)


            Remove "New Record/Request"

            “Go to Portal Row [Last]” is executed, error code 3

            “Set Field…”  “Save”record prompt

            Click “Save”

            “Go to Record/Request/Page [Next; Exit after last]”

            Goes to the Loop


            I don't see any new records added to the portal and nothing looks like it was changed.

            I'm missing something, can you tell me how I can better troubleshoot this problem?


            I'm just trying to create a blank log template for each of the 31 students populating the StudentID and auto-entered creation date fields.


            Thanking you in advance,


            <!-- EndFragment -->


            • 3. Re: script to insert rows for subset of data

              New Record/Request creates a new record in whatever table is referred to by your layout, not a new record in your portal. That's why I didn't include this step in my example. You are correct to take this step out.


              Your portal has to be based on a relationship that permits the creation of new related records. In browse mode, do you see a blank row just below the last listed entry in the portal? If so, can you enter data manually into this row? If you can't do this then either your key field in the portal table is a calculation or you haven't enabled the creation of related records in the relationship you defined in Manage | Database | Relationships.


              Another possible issue: Do you have more than one portal on your layout? If there are, then you need to tell filemaker which portal you want to input the data into in your script. Insert a Go to field step just before Go to portal row and specify a field that is present only in the portal you want to use.

              • 4. Re: script to insert rows for subset of data

                Yes, it works!  I had to create an layout with the portal and as you stated added the "Go to field step just before Go to portal row".


                Thank you very much for your patience, time and solution.