1 2 Previous Next 18 Replies Latest reply on Dec 14, 2016 3:28 PM by philmodjunk

    Script hangs with command-flashing period on screen

    FrankFarmer_1

      I have a fairly short script with two loops (nested), both start and end with Loop and End Loop commands. The inner loop's last command is Read Record/Request/Page [Next; Exit after last]. They work correctly and the final results are correct. The second (outer) loop's End Loop command is followed with an Enter Preview Mode command so the resulting report will display properly. However, it never gets there.

       

      The process hangs up after, it seems, processing the final record. A command symbol with flashing period appears on my screen indefinitely (forever!). If I press Commond+Period on keyboard, my report appears in Browse mode. Then, if I click on screen menu View>Preview, the report appears as I want it.  All the data is correct. But the script never does this final Enter Preview Mode step for me.

       

      After it's processed the final record, why would it get hung up? All suggestions appreciated.

        • 1. Re: Script hangs with command-flashing period on screen
          philmodjunk

          If you have FileMaker Advanced, run the script with the debugger enabled.

           

          Somehow, you appear trapped in a loop that never exits.

           

          A common "gotcha" that can surprise any of us is that a script can trip script triggers--which then pause the current script and do their thing before completing and returning control back to the original script. Someties this can result in a loop where the same trigger or "chain" of triggers keeps getting tripped over and over again. Using the debugger is the easiest way to find out if this is the case and to identify the triggers and scripts responsible.

           

          Note that there are ways to disable trigger performed scripts from another script to keep this kind of thing from happening.

          • 2. Re: Script hangs with command-flashing period on screen
            philmodjunk

            Another possibility is that your script may never have the last record in your found set as the current record when it reaches that go to record.. step. Some other step may have changed which record is the current record on you.

            • 3. Re: Script hangs with command-flashing period on screen
              David Moyer

              Hi,

              The inner loop's last command is Read Record/Request/Page [Next; Exit after last].

              Does the outer loop also use this method of advancing and exiting?

              • 4. Re: Script hangs with command-flashing period on screen
                FrankFarmer_1

                No, I only have the Read Record inside the inner loop, because after it reaches the last record of the inner set, I don't want it to read another record again (ie. skip a record) in the next set (outer loop). Would that happen?

                 

                What I'd like to see is an Exit Loop If command that has a parameter of "after last record".

                • 5. Re: Script hangs with command-flashing period on screen
                  erolst

                  FrankFarmer_1 wrote:

                   

                  What I'd like to see is an Exit Loop If command that has a parameter of "after last record".

                  Get ( RecordNumber ) = Get ( FoundCount )

                  • 6. Re: Script hangs with command-flashing period on screen
                    David Moyer

                    I think we're going in this direction:

                    • 7. Re: Script hangs with command-flashing period on screen
                      FrankFarmer_1

                      Thanks for your response.  I don't have Advanced. I'm using FM10 Pro.

                       

                      I've inserted Pauses to try to identify where the hangup happens. It gets through all the record processing OK, but after the last record it hangs.

                       

                      The script structure is like this (simplified)...

                       

                      Go to Layout....

                      Show All Records

                      Enter Find Mode

                      Perform Find

                      Sort Records   (by outer/primary key, then inner/secondary key field)

                      Enter Browse Mode

                      Go to Record/Request/Page [First]

                      Loop

                        ..several Set Field commands to initialize global fields

                        Set Field [GLOBALS::gKeyfield; TRANSACTION::Keyfield]

                        Loop

                            Exit Loop If [TRANSACTION::Keyfield ≠ GLOBALS::gKeyfield]

                            ...several Set Field (calculation) commands...

                            Go to Record/Request/Page [Next; Exit after last]

                          End Loop

                      End Loop

                      Enter Preview Mode

                       

                      How can I exit the outer loop after the last record has been processed? I suspect it now exits the inner loop after the last record, and returns to the start of outer loop, but there's no further records to process, so it hangs. I need a simple Exit after last record!!

                       

                      I've even tried putting these loops into a sub-script then Perform that script from this one. Same result.

                      • 8. Re: Script hangs with command-flashing period on screen
                        erolst

                        You want this:

                         

                        Go to first record

                        loop

                        # step through records ...

                        Loop

                           Exit loop if [ some pre condition ]

                             Set fields # on this record

                            Exit loop if [ some post condition]

                          End loop # inner

                          Go to next record [ exit on last ]

                        End loop # outer

                         

                        But why exactly are you using an inner loop if you're explicitly setting some fields per record? This would make sense if you had, say, a dynamic field in combination with Set Field by Name.

                         

                        Why not

                         

                        go to first

                        loop

                          initialize

                          if [ some condition ]

                            set some fields

                          end if

                          go to next record [ exit after last ]

                        end loop

                        • 9. Re: Script hangs with command-flashing period on screen
                          flukey

                          If I understand you correctly, to exit the outer loop simply add a Exit Loop If [1] statement after the end of the inner loop.  This will force the outer loop to exit.

                          • 10. Re: Script hangs with command-flashing period on screen
                            FrankFarmer_1

                            I have two loops because the records are in groups, and I process records within a group, but then I need to initialize some global fields back to zero (or whatever) when starting the next group. So the record processing happens in the inner loop, while the group processing happens in the outer loop.

                             

                            It seems FileMaker automatically "reads" the next record every time it loops. I wonder if the Go to next record command causes it to read another record (skipping the record it would have automatically read anyway). This doesn't seem to be the case, but I wonder. I always carefully check the results to ensure I get what I want or expect. It's very easy to produce a report that looks good, but really has erroneous figures because of the mysterious ways FM operates.

                             

                            The results I'm getting on this particular report are correct (after lots of hair pulling!) but I still have the inconvenience of having to press Command+Period at the end and clicking on View>Preview Mode to see my final report.  It should automatically go to Preview mode at the end of my script with the command Enter Preview Mode. This bit is not happening, even after following advice of others, so far, in this discussion. Strange! The tips are very logical, but still no luck.  I appreciate your time. Thanks!

                            • 11. Re: Script hangs with command-flashing period on screen
                              FrankFarmer_1

                              Thanks for your tip!  Very logical. I tried it, but unfortunately still no luck. I even wondered if the record count was off by 1, in case the Go to next record command registers a count. So I also adjusted the the RecordNumber by +1 (and also -1) when comparing with FoundCount, but no difference. The script still hangs at the end. Very strange.

                              • 12. Re: Script hangs with command-flashing period on screen
                                FrankFarmer_1

                                If I move the Go to next record (exit after last) command from the end of the inner loop, to the outer loop, it seems to make no difference. The final report looks exactly the same. But the script still hangs at the end.  It just doesn't seem to want to exit that outer loop.

                                • 13. Re: Script hangs with command-flashing period on screen
                                  FrankFarmer_1

                                  I wonder if I even need that Go to next record command. FM seems to "read" records automatically every time it loops. What I like about that Go command is the 'exit after last' parameter.  Why doesn't that exist in the Exit Loop If command??

                                  • 14. Re: Script hangs with command-flashing period on screen
                                    David Moyer

                                    can you post your script?  Usually the outer loop (also) contains a/the Go To Next Record.

                                    1 2 Previous Next