8 Replies Latest reply on Jan 13, 2016 9:06 AM by Abingdon

    Deleting all related records via a script

    Abingdon

      Is there a way to delete all a record's related records without doing a GTRR step and deleting them once the user is in the related records' layout?  I need to keep the Parent record so I cannot do it through the relationship set-up.

       

      Thank you as always.

        • 1. Re: Deleting all related records via a script

          Why not make (or go to) a layout based on the child record. The script would go that layout, find the records and delete them. Then exit the script.

          • 2. Re: Deleting all related records via a script
            macwombat

            Hi.  If your parent to child relationship is set up to "Delete related records ..." on the child side (see screenshot)

            Screen Shot 2016-01-13 at 11.09.34 PM.png

            then you could have the child records displayed in a portal, create a script that loops through the portal rows and deletes them.  That's a pretty cumbersome way of doing it.

            It would be easier and better to do a GTRR and delete them in the related records layout.  This will not delete the parent record.  Then return to your original layout.  Your parent record should be there.

            Chris

            • 3. Re: Deleting all related records via a script
              Abingdon

              Thank you both.

               

              I am currently doing the GTRR delete as I need to keep the parent record so the relationship delete won't work for me in this instance.  As part of this database is on WebDirect I was wondering if was possible to do the deletes without having to go to the child layout and have WebDirect have to redraw both screens when it goes and comes back again.  You right about the Portal method too Chris, a bit clunky.

               

              GTRR it is then!

               

              Thanks again.

              • 4. Re: Deleting all related records via a script
                ninja

                You can make a simple blank layout just for this purpose to speed things up...there is still some "redraw", but it can be minimal...you don't even have to have any fields on that layout for the child table.

                • 5. Re: Deleting all related records via a script
                  Mike Duncan

                  Another option... you can have a utility table where you can deposit a single record, and that table would have a cartesian relationship to the child table with cascading deletes turned on (DANGER, USE WITH CAUTION!)

                   

                  Since the cartesian matches all records, if you delete one record in the utility table, all records in the child would get deleted.

                   

                  That way this could all happen without leaving the context of the current record. Create utility record in a portal, then delete that portal row...

                   

                  Hope this helps (maybe)

                  Mike

                  • 6. Re: Deleting all related records via a script
                    Abingdon

                    Thank you.  The blank layout is in place.

                     

                    Mike, that is an interesting idea.  However, this is a multi-user database.  Wouldn't a Cartesian delete everyone's records?

                     

                    However, maybe non Cartesian relationship to the utility table and out through to the child records may work though?  It would only delete a specific user's records (each user's log-in creates a session-specific record that gets deleted when the user logs out).

                    What do you think?

                    • 7. Re: Deleting all related records via a script
                      ninja

                      Not knowing how much info is on the parent record...you could also duplicate the parent, then delete the duplicate and have it wipe the children that way...

                      All you really need is a second parent related to the same children...

                      This should not be construed as spousal abuse....

                       

                      Just thinking out loud...

                      • 8. Re: Deleting all related records via a script
                        Abingdon

                        Yes, that's a good idea.

                        And it does generally take two parents to make a child...