7 Replies Latest reply on Mar 20, 2017 5:44 PM by BruceRobertson

    Creating a new record inside a portal where the portal is inside a tab

    vickie.w

      Hi,

       

      I would like to be able to add a button to a portal inside a tab so I can go to create a new record inside the portal. I am comfortable that my relationship is doing what I need and I can add a record to the end, but, as there are sometimes quite a few child records, I would like a couple of buttons to control the behaviour "Go to Last", "Add New" "Go to First" etc.

       

      At the moment a button added just creates a new parent record. :-(

       

      Regards,

       

      Vickie

        • 1. Re: Creating a new record inside a portal where the portal is inside a tab
          Jason Wood

          You've already turned on the ability add related records via the relationship (you mentioned you can add records "at the end"), so to add a new record, you could just go to that record.

           

          If you only have 1 portal on the layout, it could be

          Go to Portal Row [Last]

          Go to Field [fieldname]

           

          If you have more than 1 portal on the layout, you need to assign a "name" to your portal in the inspector, and add one more script step at the beginning of the script:

          Go to Object [portalName]

           

          If you didn't have create related records turned on, or if for some reason you want to actually create a new record anyway (perhaps you want it sorted to the top row) your button script would look more like this:

           

          Set Variable [$id ; id of current record]

          Go to Layout [layout for child record]

          New Record/Request

          Set field [foreign key field ; $id ]

          Go to layout [original layout]

          • 2. Re: Creating a new record inside a portal where the portal is inside a tab
            philmodjunk

            I recommend that you WebSearch the MagicKey method as it's a better option for creating new records in a related table.

             

            Scripts that interact with a portal by going to specific portal rows are "brittle". They are vulnerable to failures caused by future layout changes and trip a number of script triggers--and a script trigger could be added to the layout in the future that then interferes with your script.

             

            Changing layouts resets the tab panel and portal scroll bar. You can use go to object to bring the correct panel back, but your portal may now be scrolled in an undesirable position. Even if that's not an issue, changing layouts. (Or opening a new window and changing layouts) can also trip a number of script triggers.

             

            MagicKey avoids all of these issues, but does require adding a new relationship in addition to the one used for your portal.

            • 3. Re: Creating a new record inside a portal where the portal is inside a tab
              vickie.w

              Hi Philmodjunk,

               

              Thank you for you reply.

               

              If I understand you correctly, you are suggesting using Magic Key to

              essentially scroll through all records in a related table inside a portal

              until the script finds a row that is not populated? Requiring another table

              and relationship?

               

              I think I understand the theory, if not the mechanics of making this work.

               

              Thank you for your advice.

               

              Regards,

               

              Vickie

              • 4. Re: Creating a new record inside a portal where the portal is inside a tab
                philmodjunk

                That is not how MagicKey works. It uses a relationship separate from the one used for the portal to directly create new records in the same table as that used as the source of records for the portal.

                • 5. Re: Creating a new record inside a portal where the portal is inside a tab
                  Jason Wood

                  My opinion is that if you are a beginner, hold off on MagicKey at least until you are very comfortable with the more basic methods. You almost certainly have bigger fish to fry throughout your solution and this could be a recipe for frustration.

                  1 of 1 people found this helpful
                  • 6. Re: Creating a new record inside a portal where the portal is inside a tab
                    philmodjunk

                    The steps needed to implement MagicKey are really no more complex than the alternatives and they avoid a number of issues that can occur with those alternatives. I will agree that it's harder to understand how it works though.

                     

                    If you want to try it, here are step by step instructions for setting up MagicKey:

                     

                    I am assuming the following relationship. Modify the following instructions to use your table occurrence and field names in place of mine:

                     

                    LayoutTO::__pkLayoutTableID = PortalTable::_fkLayoutTableID

                     

                    1. Open Manage | Database | Relationships
                    2. Find the Table Occurrence (the box) you selected for your portal when you added the portal to your layout and click to select it. Then make a copy of it by clicking the duplicate button (two plus signs). This does not duplicate your table. It just adds a "box" to your relationships graph that refers to the same table so that you can add a different relationship to it than that used for the portal. DoubleClick this box to open a dialog where you can rename it to be: PortalTable|MagicKey.
                    3. Your portal's table needs a primary key field that auto-enters a value each time a new record is created in it. If you do not have such a field, add a number field to that table and set it up to auto-enter a serial number. (A text field that auto-enters a UUID string could also be used).
                    4. Now add a field of the same data type (number for serial number, text for UUID if you use that) to your layout's table.
                    5. Return to the relationship graph and drag from this new field in your layout's table occurrence to the new occurrence of your portal's table. I'll call it MagicKey for clarity here.
                    6. Double click the relationship line that you just created and select the "allow creation..." option for the new table occurrence.

                     

                    Now return to your layout and use the following code to add a new record to the portal's table:

                     

                    Set Field [LayoutTable::MagicKey ; "" ]
                    Set Field [PortalTable|MagicKey::_fkLayoutTableID ; LayoutTable::__pkLayoutTableID ]

                    Commit Records

                     

                    The above will cause one new, blank portal record to appear in your portal. You can add more set field steps to add data to more fields in the new record as needed. You cannot create a new related record until you clear the MagicKey field again by setting it back to "".

                    1 of 1 people found this helpful
                    • 7. Re: Creating a new record inside a portal where the portal is inside a tab
                      BruceRobertson

                      In another thread, I posted a  file that demonstrates a few things including the method Phil describes.

                      You might download it at and take a look.

                      It is the attachment in this message:

                       

                      Re: One window - three layouts