3 Replies Latest reply on May 2, 2016 8:05 PM by jbrown

    How to create new related record from popover

    user26927

      Hello

       

      I am trying to create a new related record from a popover window. 

       

      I have accounts and contacts. 

      In the accounts layout...I have portal showing all related contacts. 

      I am trying to create new related contact records from the accounts layout. 

       

      I have a popover window with global contact fields like first name, last name, email. 

      There is a save button at the bottom of the popover that runs a scrip which sets the fields from the global fields entered in the popover.  The popover has an on object exit scrip that clears the global values. 

       

      Everything works...ONCE.  When I try to create a second related contact from the popover...it just alters the first contact record I created. 

       

      What do I need to do to make this work?

       

      Thank you kindly

        • 1. Re: How to create new related record from popover
          jbrown

          Hi.

          The script that runs when you press a button should do the following:

          1. Grab the ID from the account record you're on in a variable. I use $ID as the variable

          2. Go to a layout of the child table

          3. Create a new record

          4. Set the foreign key field to the value in the $ID field

          5. Set the other fields to the globals.

          5.5 Commit the record.

          6. Go back to the layout you were originally on.

          7. Clear the globals.

           

          If the first child record is being modified with the data from the 2nd try, that makes me think you're not either creating a new record or you are modifying the values in the portal. Without specific direction, the script will set the fields in the first row of the portal.

           

          I never use a portal to set fields. I always use the method described above to create related records.

          • 2. Re: How to create new related record from popover
            user26927

            Thank you. Can you explain variables please?

            • 3. Re: How to create new related record from popover
              jbrown

              A variable is simply a piece of memory that holds a value. Its a typical technique of FileMaker developers to store data into variables and use it elsewhere.

               

              Check out the demo file I have here. This demos what you're trying to build. I use a variable called $ID to hold the primary key so that I can use it to create a new record in the child table.

               

              And, if you havent done so, I recommend you read the FileMaker Training Series. It talks about variables and how to use them throughout your system.