8 Replies Latest reply on May 14, 2014 1:40 PM by philmodjunk

    Popover Button Behavior for adding record in a related table

    BillPlunkett

      Title

      Popover Button Behavior for adding record in a related table

      Post

           Thanks to Phil's expert demo on how to make a filtered portal  work on a keystroke basis, I'm on to my next problem I can't make work.

           I have a popover button on the same donation layout to add a new donor - the Donor table is a related table and not the base table of the layout.  So with a script trigger of OnObjectEnter I run a script that goes to a layout with Donors as the base table and add a new record then return to the original layout.  But when I return, the popover screen is gone.  How do I redisplay the popover which will contain name and addr fields for the newly added donor?

           thanks again for all the great help I get on this forum...

        • 1. Re: Popover Button Behavior for adding record in a related table
          philmodjunk

               If you assign an object name to the popover Frame (not the button), go to object can re-open the popover just as Go to Object can select the panel of a tab control.

               It's also possible to create a new Donor record without changing layouts if you set up the correct relationship for that purpose.

          • 2. Re: Popover Button Behavior for adding record in a related table
            BillPlunkett

                 I WOULD like to add the record to the Donor Table from the Popover.  I have the checkbox checked to allow additions via the relation but the add new record script step doesn't have a way to specify which table.  So how do I do that?

            • 3. Re: Popover Button Behavior for adding record in a related table
              philmodjunk

                   You use a relationship specifically set up to permit creating a new record in the related table.

                   Starting with this relationship:

                   Donors-----<Donations

                   Donors::__pkDonorID = Donations::_fkDonorID

                   add another occurrence of Donors:

                   Donations-----Donors|Create

                   Donations::cNewKey = Donors|Create::NewKey

                   With "allow creation..." enabled for Donors|Create and cNewKey defined as a calculation field that evaluates to 1 or any other constant value.

                   Then this script can create a new record in Donors from the Donations layout:

                   Set Field [Donors|Create::NewKey ; Donations::cNewKey ]
                   Set Field [ Donors|Create::NewKey ; "" ]

                   The second set field step clears the NewKey field in the new record so that the relationship once again matches to no records in the Donor table. That way, the first set field step can be used again to create a new record.

                   Between those two steps, you may want to use Set Variable to capture the value of of the __pkDonorID field of this new record or do a new Record/Request followed by a set field step to create a new donations record that is properly linked by DonorID before severing the link to the new record by clearing the NewKey field.

                   Note: I dreamed up this approach a while ago as the increasing use of script triggers is creating issues with the standard, change layouts, create a new record and change back script as it can trip a very large number of different script triggers in either layout--creating sometimes hard to diagnose issues with the original script. (And can also create issues with portals and popovers not retaining their correct state.)

                    

              • 4. Re: Popover Button Behavior for adding record in a related table
                BillPlunkett

                     OK Phil, I get all of your process EXCEPT how to actually create the new record in the scripts?  I don't see how it would cause a record to be added without the new record request.

                     Could you please explain the process a little more.

                     thanks so much

                • 5. Re: Popover Button Behavior for adding record in a related table
                  philmodjunk

                       New Record/Request is not the only script step that can create a new record in a table.

                       Set Field [Donors|Create::NewKey ; Donations::cNewKey ]

                       Creates the new record in Donors.

                       This method will create exactly one related record as long as the relationship from Donations to Donors|Create does not match to any related records. It is similar to creating a new record in a portal by entering data in the bottom "add row" of the portal and relies on the same relationship details in order for it to work.

                       The following script step:

                       Set Field [ Donors|Create::NewKey ; "" ]

                       Then disconnects the newly created record so that the first set field can once again create a new record in the Donors table.

                  • 6. Re: Popover Button Behavior for adding record in a related table
                    BillPlunkett

                         I'm almost there.  The new Donor is being created correctly but when the script ends and I need to enter the Name and Address for the newly created Donor, the edit fields on the layout are locked.

                         The fkDonorID field displayed (small red circle on image) is from the layout's base table - GeneralDonations, and is displaying correctly.  I added a script step to the end of the script:   Set Field[GeneralDonations::fkDonorID; Donors|Create::pkContactID]

                         The Name and Addr text fields on the layout (large red circle) are from the T.O. for donors setup to display the related records from the portal on the left.  The portal you helped me to actively filter by keystroke.

                         I'm guessing it is something with the T.O.s that is out of sync but I can't complete the process...

                         thanks again for your help once again...

                    • 7. Re: Popover Button Behavior for adding record in a related table
                      BillPlunkett

                           Actually, I got it to work by adding a "commit record request" to the end of the script.

                           So, it all seems to be working now,

                           thanks so much for all your help!!!

                      • 8. Re: Popover Button Behavior for adding record in a related table
                        philmodjunk

                             And from what table occurrence are you selecting those fields from Donors?

                             You can't use Donors|Create because the follow on set field step clears the NewKey field and removes the link from your current Donation record to that new donor record.

                             You can't use Donors because the script does nothing to link Donations to that new record in donors.

                             That's why I posted this text in my first post:

                             

                                  Between those two steps, you may want to use Set Variable to capture the value of of the __pkDonorID field of this new record or do a new Record/Request followed by a set field step to create a new donations record that is properly linked by DonorID before severing the link to the new record by clearing the NewKey field.

                             Before you can access fields of that new record, one method or another must be used to link your current donations record to that new Donor record.

                             Another option is to leave out the last set field step in this script and use a separate script to clear the NewKey field using the OnObjectExit trigger on the popover frame to perform that script.

                             But I can't help feeling that there is some missing info here. You are on the donations layout and you want to add a new donors record. Once you've added that new donor record, what happens next? Won't you then want to create a new donation record linked to that new donor record?