3 Replies Latest reply on Jul 23, 2017 10:27 AM by SteveMartino

    Set Child fk to Parent PK

    cmj

      Still a new to FM but eager to learn. FM ver 11

      My tables contain a Parent table that's connected to a Child table in a one to many relationship.

      The Parent table will always contain only 1 single record.

      I have created a separate layout (list view) for the Child records. When I create a new child record in this layout I want to populate the field fk_parentID with the ID of the Parent table, field PK_parent ID.

      I don't want to use a portal for reasons that relate to layout functionality shortcomings.

       

      Thanks

        • 1. Re: Set Child fk to Parent PK
          cmj

          I found a way to accomplish this but have reservations about the answer:

          In the child table, field fk_parentID -  I set the field to a calculated value that = 1. Works fine but if the parent table record is ever changed and does not = 1, the solution will not work. Yes there will always be only 1 record in the parent table... Is there a script or some other method that I can pick a singular ID in the parent table?

          • 2. Re: Set Child fk to Parent PK
            CarlSchwarz

            cmj wrote:

             

            The Parent table will always contain only 1 single record.

            I have created a separate layout (list view) for the Child records. When I create a new child record in this layout I want to populate the field fk_parentID with the ID of the Parent table, field PK_parent ID.

            I don't want to use a portal for reasons that relate to layout functionality shortcomings.

             

            Thanks

            Usually when you go from a parent record to the children record(s) you will store that Parent PK in a variable or global field somewhere and manually populate that to any new child records via a script or calculated value as you have.

            Unless the layout has some context (e.g. viewing a parent record and showing children in a portal) you will need to store that context and manually enter it as you have.  Controlling the UI flow is what makes this out-of-context stuff work.

            1 of 1 people found this helpful
            • 3. Re: Set Child fk to Parent PK
              SteveMartino

              Here's another way you may be able to adapt.  Look at the sample file about 3 posts down:

              Add New Portal Row With Script

              Although it says you're adding a portal row, you are actually making a new related record.