10 Replies Latest reply on Jul 10, 2016 5:01 PM by russk68

    Auto create records based of a fields value

    russk68

      Hi all,

      I want to create new records from a value in a field from another table. I am trying to create the script myself but I don't see the option to add more than 1 new record.

      Example:

      I have a field to enter the amount of guests attending an event =30

      I have another table for guest info and I want a script to create (30) new records from the value of the field of guests attending.

       

      Thanks in advance!

       

      Russ

        • 1. Re: Auto create records based of a fields value
          BruceRobertson

          What does your script look like so far?

          • 2. Re: Auto create records based of a fields value
            russk68

            Hi

            I haven't started one because I don't see an option for what I am looking for and wasn't sure if it's even possible to do. I am a novice at this.

            • 3. Re: Auto create records based of a fields value
              ron.harris

              Hi Russ,

              I'm new to FMP and perhaps my note here is useless but, here I go any way...

               

              My first thought was iteration so I looked in the Script Steps and found in the Control category of Script Steps Loop/Exit Loop/End Loop steps.  Though I'm not versed in this scripting language, I would think you could nest your creation of records in the loop.  I'm sure it goes without saying, but, make sure you provide an exit strategy for the loop.

               

              Experts; if my assumption is incorrect please let me know.

               

              Bruce helped me yesterday so I think your in good hands.

               

              Ron Harris

              • 4. Re: Auto create records based of a fields value
                russk68

                Hi Ron,

                I'll give it a whirl.

                 

                Thanks for the input!

                • 5. Re: Auto create records based of a fields value
                  BruceRobertson

                  Some questions. You already have the list of thirty names? Normally you do not just create X blank records then populate them. What is the bigger picture here?

                  That said, the loop, exit loop if structure would work.

                  • 6. Re: Auto create records based of a fields value
                    russk68

                    No, but there is information that I want carried over as well.

                    Example: The 30 guests attending are from NY and the guest info table will have 30 records with the state auto filled.

                     

                    I will then create another record with guests attending from NJ and the value in the field with the number of guests will add records to the guest info table as well with NJ autofilled for each record.

                    Hope this makes sense.

                     

                    The script I have so far:

                    Set Selection (Selects the field with # of guests. I need to paste this value but don't know where)

                    copy (Copies the # of guests)

                    Go to Layout

                    New Record/Request (Thought I could paste the # of Records somehow)

                     

                    Any and all help is greatly appreciated!

                    • 7. Re: Auto create records based of a fields value
                      BruceRobertson

                      No, you do NOT need to copy/paste and that is one of the first lessons of scripting.

                      There are very very very few reasons to ever use copy/paste in scripts.

                       

                      Set selection is also the wrong script step.

                       

                      It would be helpful if you would provide much more description of your tables and fields as they exist so far.

                      You may even want to post your files.

                      Note that you can post a clone of your files (a copy of the file with no data).

                      There is quite a lot of missing information here.

                      Most likely they will need improvement.

                      Anyway: here is a basic loop structure with a calculated exit condition.

                      Note that "yourFieldThatHoldsCount" and "layoutForNewRecords" are phony field and layout names.

                       

                      Set Variable [ $max ; yourFieldThatHoldsCount ]

                      Set Variable [ $counter ; 0 ]

                      Go to Layout [ layoutForNewRecords ]

                      Loop

                        Exit Loop If [ Let( $counter = 1 + $counter; $counter > $max )]

                        New Record

                      End Loop

                      • 8. Re: Auto create records based of a fields value
                        russk68

                        I tried Ron's suggestion and got stuck in a loop and so I went in another direction but I see he was on the right track.

                        I will give this a try.

                        I created a massive Excel spreadsheet for concert lighting production paperwork with 1000+ hrs invested. It works very well but has it's limitations and it sometimes takes hrs to make a change because I sometimes have to change formulas in every cell. I have a feeling that I will be here quite often looking for help so I will figure out how to post my files.

                        Thank you!

                        • 9. Re: Auto create records based of a fields value
                          ron.harris

                          BruceRobertson wrote:

                           

                          No, you do NOT need to copy/paste and that is one of the first lessons of scripting.

                          There are very very very few reasons to ever use copy/paste in scripts.

                           

                          Set selection is also the wrong script step.

                          This is very helpful information for those of us whom have never written FMP Script.

                           

                          Ron