9 Replies Latest reply on May 10, 2012 4:01 PM by lmflora

    creating multiple records from a value list

    lmflora

      Title

      creating multiple records from a value list

      Post

      Hi,

      I need a script where i can create 25 records at one time, each of these 25 records would have one field with a unique text identifier-extracted from a value list. The number of new records would match the number of items on the value list. I have found a similar post where a script was written using the "set variable" and loop function.  here is the link to that post:

       

       

      I cannot seem to get this to work, i get the command symbol working endlessly and I must force quit and trash what is now a corrupted file.

       

      my goal is as follows:  I want to push a script button to create 25 records where:

      record #1   name = "FEID",  date = "todays date",

      record #2  name = "ELSP"  date = "todays date"

      record #3  name = "ZIVE"  date = "todays date"

       

      and so on to record #25.

      the names FEID, ELSP, ZIVE come from a value list (or related file), there are 25 names-thus 25 new records.

      I need this to work on FileMaker GO as well. 

      I would be very grateful if anyone can help me sort this out.

        • 1. Re: creating multiple records from a value list
          philmodjunk

          Please post the actual script that you have wirtten. It sounds like you are either missing an exit loop If step or the expression within never evaluates to "True" and thus your loop never ends.

          To post a script to the forum:

          1. You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
          2. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
          3. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
          4. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)
          • 2. Re: creating multiple records from a value list
            lmflora

            Hello,

            Here is the script that I am trying to get to work.  Thank you for your help! It is likely that I am not using the set variable script step correctly.  the value (pm_spp::Species) is a link to the related file with the list of name codes with which I want to create the 25 records.

             

            Set Variable [ $sppname; Value:pm_spp::Species ]

            Loop

            New Record/Request
            Set Variable
            [ $sppname; Value:$sppname-1 ]

            Exit Loop If [ $sppname=0 ]

            End Loop 

            • 3. Re: creating multiple records from a value list
              philmodjunk

              Set Variable [ $sppname; Value:pm_spp::Species ]
              Loop
                 Set Variable [$K ; $K + 1]
                 New Record/Request
                 Set Field
              [ YourTable::NameField ; GetValue ($sppname ; $K ) ]
                 Exit Loop If
              [ $K > ValueCount ( $sppname ) ]
              End Loop

              This assumes that pm_Spp::Species stores a list of names separated by returns.

              • 4. Re: creating multiple records from a value list
                lmflora

                Ok,

                Thanks-your awesome

                It doesn't crash anymore.  i can get it to create 1 record at a time, but it does not fill in the name field with the spp code. for  the pm_Spp::Species field---- I have tried two ways, 1) as one record with one field with all 25 values in it seperated by a return, and 2) as a file with 25 separate records with each code in a unique record.  How do I get it to retreive the name value?

                • 5. Re: creating multiple records from a value list
                  philmodjunk

                  I would guess from what little that I know about your database that you need to start this script from a layout based on the pm_spp table and the script needs to change layouts in order to create records in the other table. 

                  #start script on layout for pm_Spp
                  Freeze Window
                  Set Variable
                  [ $sppname; Value:pm_spp::Species ]
                  Go to Layout [ Specify new layout to table where records will be created here.]

                  Loop
                     Set Variable [$K ; $K + 1]
                     New Record/Request
                     Set Field
                  [ YourTable::NameField ; GetValue ($sppname ; $K ) ]
                     Exit Loop If
                  [ $K > ValueCount ( $sppname )]
                  End Loop
                  Go to Layout [original layout]

                  Keep in mind that this script still assumes that the entire list of names is stored in a single record in the pm_spp::Species field.



                  • 6. Re: creating multiple records from a value list
                    lmflora

                    Hello,

                    It works great. Thanks.  How do I get it to insert the current date into each of the records? Do I put the insert current date step within the same loop or a different loop?

                    • 7. Re: creating multiple records from a value list
                      lmflora

                      I figured it out.  I just added insert current date, and replace field contents to populate the date.  

                       

                      Thank you so very much for helping me sort this out.  I have been fretting over this for awhile.  This will make a big difference in my day.

                       

                      Have a great day!!

                      LM

                      • 8. Re: creating multiple records from a value list
                        philmodjunk

                        I wouldn't do it that way. You can set up field options on the date field to automatically enter the creation date. That way you get the date in this field whether you use this script or use other means to create the record.

                        Replace field contents, BTW, should be used with care. It will update every record in your found set--which could easily be more records than you intended to update with the current date.

                        • 9. Re: creating multiple records from a value list
                          lmflora

                          Thanks you are right again! It would be a disater if i updated the date of unintended records. I have yet to try it out in FileMakerGo. 

                          Have a great evening

                           

                          LM