1 Reply Latest reply on Jan 27, 2011 12:47 PM by philmodjunk

    Script Triggers and unwanted looping



      Script Triggers and unwanted looping


      Hi folks ... after 5 hours of solid head beating, googling, experimenting and no luck ... I turn here.

      I have a script that works well when fired manually.  But if I try to use it as a layout script trigger it loops.  I understand why (I think) but I can't devise a work around.

      Here's the background.

      - I have two tables (Clubs and People)

      - records in each table contain geocode information (latitude/longtitude)

      - I can run a script that determines the Person's location and can then calculate a secondary set of latitudes and longitudes that represents a 50 mile radius.  (ie if latitude was 10.0 and I calculate latitude-variation and latitude+variation I will get a search string of for sake of arguement 8.5 ... 11.5)

      - I can then plug this search string into the Clubs table and find the clubs that exist within that 50 mile radius.  I give this foundset a global value (2)

      - In my People page I have a portal that displayes these results based on a relationship where the People page also has a global value of (2).

      Here's the problem

      - If I run this script manually, no problem.  Works slick

      - But I want to be able to advance record by record in the People section and have the portal populate with the Clubs in the vicinity of the Person.

      - The rub seems to come when it flips from layout to layout (even though it's faster than the human eye) it repeatedly sets off the trigger.  Hence the loop

      - I've tried OnRecordLoad, OnRecordCommit, OnLayoutLoad and even OnModeEnter.  Same results.

      - I can't seem to be able to set the fields for the find request without switching to the Club layout and then I have to switch back to the People layout to see the results in the portal.

      Any suggestions or work arounds?  I appreciate you consideration.


        • 1. Re: Script Triggers and unwanted looping

          You might be able to design a relationship for your portal that does not require any script. I'd make that the best option if it can be done.

          You can also avoid tripping repeated triggers by using a global variable and enclosing your variable in an If block that only allows the script to trigger if it isn't a "repeat" call of the trigger.

          If [Not $$Repeat]
            Set Variable[$$Repeat ; True ]
            //yourscript here
            Set Variable [$$Repeat ; False ]
          End IF

          Be careful of steps within your script that may also trip the trigger by changing record or layout. You may have to add additional Set Variable steps to keep the script from performing when you don't want it to.