2 Replies Latest reply on Jun 12, 2014 9:30 AM by sccardais

    Getting infinite loop from On Layout Load Script Trigger

    sccardais

      Title

      Getting infinite loop from On Layout Load Script Trigger

      Post

           The script shown below is creating an infinite loop.

           The script runs whenever a sub summary layout named "Ranking of Issues" is loaded. This layout is based on a child table named "Issues". Some values in the Ranking of Issues are calculated based on a related parent table, Surveys.

           To get the value from the parent, I *think* I need to temporarily open a layout in the parent, perform a find, set a variable and then return to the layout based on the child.

           When I return to the child, the script trigger activates again. Is there a way I can get the info from Table 1 without causing this loop?

           FYI: I go to Table 1 (Parent) to find all of the records in Table 1 that have at least one related record in child Table 2. This number is stored in a $$ variable that is used in Layout 2.

            

            

            

      Loop_Script_Trigger.png

        • 1. Re: Getting infinite loop from On Layout Load Script Trigger
          philmodjunk

               There are a number of ways to extract data from another table without changing layouts if you use either a relationship, relationship w/filtered portal, or a calculation using ExecuteSQL() (if you have FileMaker 12 or newer).

               To discuss those methods, I'd need to know what find criteria you are specifying inside Perform Find[Restore].

               But you can also keep one script from performing triggered scripts when it changes layouts or does other actions that trip script triggers.

               Rewrite the above script like this:

               If [Not $$TriggersOff ]
                  Set Variable [$$TriggersOff ; value: True ]
                  Go to Layout [
                  Perform Find [Restore] ---> enter find mode[] does nothing in your script
                  Set Variable
                  Go to Layout
                  Sort Records
                  Set Variable [$$TriggersOff ; value: False ]
               End IF

               Exit script is also not needed in this script as your script will exit without that added step when the last script step executes.
                 

          • 2. Re: Getting infinite loop from On Layout Load Script Trigger
            sccardais

                 Thank you. Worked perfectly.

                 FYI the find criteria  ... the Parent layout contains customer satisfaction Surveys. The layout in the parent contains a portal showing all Issues that have been assigned to each Survey. Some surveys have none.  I FIND all of the Surveys have at least one related record in the Issues table by entering * in the proper field in the portal. At the moment, 430 surveys have at least one issue but there are over 600 records in the Issues table because some Surveys have more than one issue. I store the found count in the variable $$SurveysWithIssues.

                 The Ranking of Issues layout is based on the child, "Issues" table. It ranks the Issues in descending order based on the count of each Issue in the Issues table. It also displays the percent each issue represents of the Surveys that have at least one issue. This is where the $$SurveysWithIssues variable is used.

                 So .. assume 430 Surveys have at least one issue and that there are 600 records in the Issues table and that 50 of the records in Issues table have "Reports" in the Issue field. The percentage shown in the Ranking of Issues layout for "Reports" is 50 / 430 (11.6%) not 50 / 600 (8.3%)

                 Put another way, 11.6% of the Surveys that had any issues at all mentioned Reports.

                 Thanks again for your help.