9 Replies Latest reply on Apr 30, 2013 11:08 AM by ch0c0halic

    Delete related records via script

    user18951

      I have a script snippet below, used to delete related records under certain conditions:

       

      Screen Shot 2013-04-26 at 10.34.38 AM.png

       

      I'm trying to get rid of the flash and the delay that all the new window - close window business causes.

       

      Is there a better way to do this scripted deletion without having to open a new window?

       

      Message was edited by: David Goodnature

        • 1. Re: Delete related records via script
          BruceHerbach

          Hi,

           

          Two things to try.  First add a Freeze window command before the GTRR( Go to Related Record) step.  Second in the GTRR under the new window,  set the Distance from Top field to -10000.  This will open the window 10000 pixels above the visible screen.  This will minimise or eliminate the flash.  Since no user interaction is required,  the user never needs to see the screen.

           

          Bruce

          • 2. Re: Delete related records via script
            ariley

            If you're on desktop you can just open the windows in a negative environment. We usually have a custom function called negative space and give it a -20000 value. 

             

            Doesn't work on Go, though.

             

            Say goodbye to flashes. 

             

            Best regards,

             

            Agnes Riley

            ZeroBlue

            1 of 1 people found this helpful
            • 3. Re: Delete related records via script
              DanielShanahan

              David, did you try the procedure without calling a new window?  If you are working in a LAN environment then FMP can move to various layouts very quickly without the flash.  And the user never knows the layout has changed.  Try it in a test environment and compare with using a new window.

               

              Also, a word of caution on go to related record - you may want to run an If script step to check that you really did change layouts.  If there are no related records you will get an error and proceed with the script, so there is always a chance that you will delete records in your original layout instead of your related layout.

               

              I usually do something like:

               

              GTRR

              Set Var $e = Get ( LastError )

              If $e = 0

                Delete Record(s)

              End If

              1 of 1 people found this helpful
              • 4. Re: Delete related records via script
                user18951

                Tried it.  That method is a distinct improvement. 

                 

                Still has a bit of a lag, though.  I thought it was just the flash was there issue, but there is a little latency.  (It's on a WAN, offsite server).

                • 5. Re: Delete related records via script
                  user18951

                  Agnes -

                   

                  Same answer as before -

                   

                  Tried it.  That method is a distinct improvement.

                   

                  Still has a bit of a lag, though.  I thought it was just the flash was there issue, but there is a little latency.  (It's on a WAN, offsite server).

                   

                  How would one do that if it was to be accessed by ipad using go?

                   

                  Thanks!

                  • 6. Re: Delete related records via script
                    user18951

                    Daniel -

                     

                    I'm not sure how it would work without calling a new window?  The info I'm deleting is in a portal.  I have three different portals on the page.  I'd certainly like to know how that would work.  Sounds better than going to other layouts.  The way I'm doing this now seems a little 'primitive'.

                     

                    I agree, one certainly does need to test some conditions prior to making deletions like that.  I learned that the hard way, when I unintentionally deleted a bunch of data unintentionally last week!

                     

                    Thank you!

                    • 7. Re: Delete related records via script
                      DanielShanahan

                      David,

                       

                      You could grab the primary key of the record/layout initiating the script:

                      Set Variable [$id ; PARENTTABLE::id]

                       

                      Then use GTRR to get your related records.  Once deleted, use Go to Layout to return to the parent record, perform a find on the primary key.

                      • 8. Re: Delete related records via script
                        DanielShanahan

                        As I think about it, you could also use Go to Object.

                         

                        Name the portals and name the fields in the portal.  Use Go to Object to navigate to the proper portal and then Go to Object to go to a particular field.  Run your criteria to see if you want to keep or delete.  If you want to delete, use Delete Portal Row - no dialog.

                        • 9. Re: Delete related records via script
                          ch0c0halic

                          What about testing if there are any related record before doing the GTRR and Delete? This eliminates the GTRR before testing and the IsEmpty(related::field) is optimized for responsiveness.

                           

                          If ( not IsEmpty ( GTRR_Relationship::primary_key )

                          GTRR - show only related

                          Delete record(s)

                          end if