9 Replies Latest reply on Jul 2, 2009 12:08 PM by anicolais

    Auto Populate ID#

    anicolais

      Title

      Auto Populate ID#

      Post

      Good Afternoon Everyone,

      I am trying to make a field in my database called ID#. I am trying to make it auto populate with the record number. Is this possible? Then when a button is clicked I am trying to make it go to another layout and populate the ID# on that layout with the same ID# as the record you were currently on when you clicked the button...Thus in turn relating the 2 records. Any ideas?

       

      Thanks

        • 1. Re: Auto Populate ID#
          philmodjunk
            

          The standard Filemaker way to do this is:

          Define a number field set to auto-enter a serial number--each new record thus receives a unique number.

           

          Define a relationship between the two tables and select the "Allow creation of records via this relationship" option for the second table.

           

          Now, once the new record in table 1 is created, you can create your related record simply by typing in a portal or using a set field step to set any non-blank data to any field in table 2. (Either action is performed from a layout that refers to table 1.) Both options create a record in table 2 with the serial number of the current record Table 1 auto-entered into the matching field in table 2.

           

          Is this what you had in mind?

          • 2. Re: Auto Populate ID#
            anicolais
               The only thing is I have all my accounts in the database already, and none of the contacts. I made an auto calcualted field that gets the current record for the account layout and puts it in the account ID. I have 800 acounts ID# 1-800. I made Account::ID# and Contact:ID# relate. Now I am trying to figure out a way to make it so when a button is pressed on the account page it will first find the contacts that are related to that account. If there is no contacts then I want it still to bring me to layout and when I click new record it will auto populate the Contact::ID# with the same account::ID# thus relating the records.
            • 3. Re: Auto Populate ID#
              philmodjunk
                

              "If there is no contacts then I want it still to bring me to layout and when I click new record it will auto populate the Contact::ID# with the same account::ID# thus relating the records. "

              If the layout is based on Contact and there are no matching contacts records to find, your layout will be blank until you create 1 related record.

               

              This is how I'd do it:

              Enable the "Allow creation of records..." option I posted earlier if you have not already done so.

               

              Your script for a button on your account layout:

               

              If [count(Contact::ID#) = 0 /* there are no related contact records for the current account record */]

                Set Field [Contact::ID#, Account::ID#] //this creates the new blank created record.

              end if

              Go to related record [Show only related records; from table: "contact"; using layout: "contacts" (contact)]

               

              If you want to create a new related record on your contacts layout, use:

               

              Set Variable [$ID; Contact::ID#]

              New Record/Request

              Set Field [Contact::ID#; $ID]

              • 4. Re: Auto Populate ID#
                anicolais
                   Ok lets say my account::ID# = 54. I am now trying to set it up so there is a button on my Account layout that when clicked will create a new record in the contact layout and will auto enter the 54 into Contact::ID#. While bringing the user to the new record. This is all i need to know how to do. Thanks!
                • 5. Re: Auto Populate ID#
                  philmodjunk
                    

                  Combine the two scripts so that the new related record is always created:

                   

                  If [count(Contact::ID#) = 0 /* there are no related contact records for the current account record */]

                      Set Field [Contact::ID#, Account::ID#] //this creates the new blank created record.

                  else

                     Set Variable [$ID; Account::ID#]

                     Go To layout [Contacts (contact)]

                     New Record/Request

                     Set Field [Contact::ID#; $ID]

                     Go To Layout [Origininal Layout]

                  end if

                  Go to related record [Show only related records; from table: "contact"; using layout: "contacts" (contact)]

                   

                  Note: going back to the original account layout allows go to related record to pull up existing related records and the new record in a combined found set.

                  • 6. Re: Auto Populate ID#
                    anicolais
                      

                    For some reason this wont work...the button just clicks but it does nothing. I will mess around a bit see fi I can figure something out.

                     

                    If [count(Contact::ID#) = 0 /* there are no related contact records for the current account record */]

                      Set Field [Contact::ID#, Account::ID#] //this creates the new blank created record.

                    end if

                    Go to related record [Show only related records; from table: "contact"; using layout: "contacts" (contact)]

                     

                     

                    • 7. Re: Auto Populate ID#
                      anicolais
                         sorry i didnt see what you jsut wrote I will try that
                      • 8. Re: Auto Populate ID#
                        philmodjunk
                          

                        It occurs to me we can simplify since we are now creating a new related record all the time:

                         

                        Set Variable [$ID; Account::ID#]

                        Go To layout [Contacts (contact)]

                        New Record/Request

                        Set Field [Contact::ID#; $ID]

                        Go To Layout [Origininal Layout]

                        Go To Related Record....

                         

                        Should work for you.

                         

                        If not, and you have fmp advanced, step through it with the debugger on and see where things go off the rails.

                        • 9. Re: Auto Populate ID#
                          anicolais
                             Got It. Thanks a lot for all the help!