1 2 Previous Next 15 Replies Latest reply on May 23, 2017 3:54 AM by GSalmson

    Loops continuing to loop

    GSalmson

      Hi all,

      I am just wondering if anyone has experienced this phenomenon. I have a pretty hefty script. It is 84 lines long. I won't bore you with the details, because the script works perfectly most of the time. I have filemaker pro14 set up on 4 windows 7 pc's talking with filemaker server 13. In the script is a loop segment which adds records to a related table. This all works fine, but occasionally and it is only occasionally, it appears that the loop part continues to add records. I am not sure if this is a flaw in my script (not likely as it works normally most of the time) or if it is network related or if there is some other gremlin that I can't think of.

       

      Has anyone ever experienced this?


      Regards and thanks in advance

      PMar146

        • 1. Re: Loops continuing to loop
          user19752

          How do you exit the loop? Check the condition when it continuing.

          • 2. Re: Loops continuing to loop
            GSalmson

            Hi user19752

            The loop step is quite long winded but effectively it goes like this:

             

            Loop

                Go to Layout[Layout]

                Enter Find Mode

                Set Field

                Perform Find

                    If[Get(FoundCount) ≥ 1]

                    etc

                    etc

                End If

                Exit Loop If [Get(FoundCount) =0]

                Go to Layout [Layout]

            End Loop

            • 3. Re: Loops continuing to loop
              GSalmson

              The funny part is that the extra records being added are just multiple copies of the one record.

              • 4. Re: Loops continuing to loop
                user19752

                Are there any "Omit record" thing in "etc etc", or you exit loop only if there is no found set on "Perform Find" ?

                • 5. Re: Loops continuing to loop
                  BruceRobertson
                  I won't bore you with the details...

                  OK. Then we won't bore you with a possible solution.

                  However:

                  Loop

                      Go to Layout[Layout]

                      Enter Find Mode

                      Set Field

                      Perform Find

                      Exit Loop If [Get(FoundCount) =0]

                          If[Get(FoundCount) > 0 ]

                          #does any of this involve a change of layout?

                          etc

                          etc

                      End If

                  End Loop

                  #we have exited loop; what layout are we on and what should happen next?

                  • 6. Re: Loops continuing to loop
                    GSalmson

                    There are no omit records and you only exit the loop if the found count =0.

                    • 7. Re: Loops continuing to loop
                      GSalmson

                      The original layout is resumed and there are added records to another table.

                       

                      The reason I haven't bored you with the details is that the script works very well 99% of the time. There are no notable differences in between running the script and immediately afterwards running it again and having the loop continue. Equally It is not user specific nor is it machine specific. So I am not convinced it is a scripting issue.

                      • 8. Re: Loops continuing to loop
                        user19752

                        Then if search criteria in "Set Field" have value in record, you will never exit from the loop.

                        How does the value change in loop?

                        • 9. Re: Loops continuing to loop
                          GSalmson

                          The rest of the loop is as follows.

                           

                          Loop

                              Go to Layout[Layout]

                              Enter Find Mode [Pause:off]

                              Set Field [Table::Printed; "N"]

                              Perform Find

                              If[Get(FoundCount) ≥ 1]

                                  SetVariable [$RecordID; Value: Table::RecordID]

                                  Set Field [Table::Printed; "Y"]

                                  Go to Layout ["OtherTableLayout" (OtherTable)]

                                  New Record/Request

                                  Set Field [$RecordID

                                  Go to Layout ["Printable Layout" OtherTable]

                                  Print Setup [Restore; With Dialog:off]

                                  Print

                              End If

                              Exit Loop If [Get(FoundCount) =0]

                              Go to Layout [The First Layout]

                          End Loop

                           

                          There are a few more variables in there, but essentially the loop is exited if once all the records have been printed and a copy of the record is put in another table. As I said, the script works perfectly almost all of the time.

                          • 10. Re: Loops continuing to loop
                            Philip_Jaffe

                            Move your exit loop to immediately after the perform find step.

                            1 of 1 people found this helpful
                            • 11. Re: Loops continuing to loop
                              GSalmson

                              Hi Philip_Jaffe,

                              That seems to work exactly the same as where it was before, but I will monitor it now to see that it doesn't go into the dreaded loop again. Your approach makes better sense I suppose. I guess originally it would process the IF (Get (FoundCount) <1 first and then decide nope and then use the Exit Loop If [Get(FoundCount) =0].

                               

                              This way the loop is exited quicker and cleaner.

                               

                              I guess it was the script after all.

                               

                              Thank you all again for nutting this one out.

                              • 12. Re: Loops continuing to loop
                                user19752

                                It is not "exactly" same, since Get(FoundCount) in "Exit Loop If" step run on OtherTable sometime. (But this make more "exit", not more "loop" ... )

                                 

                                I would use "Else" step.

                                • 13. Re: Loops continuing to loop
                                  keywords

                                  Here is another boring detail for you. As your script stands—

                                  Loop

                                      Go to Layout[Layout]

                                      Enter Find Mode [Pause:off]

                                      Set Field [Table::Printed; "N"]

                                      Perform Find

                                      If[Get(FoundCount) ≥ 1]

                                          SetVariable [$RecordID; Value: Table::RecordID]

                                          Set Field [Table::Printed; "Y"]

                                          Go to Layout ["OtherTableLayout" (OtherTable)]

                                          New Record/Request

                                          Set Field [$RecordID

                                          Go to Layout ["Printable Layout" OtherTable]

                                          Print Setup [Restore; With Dialog:off]

                                          Print

                                      End If

                                      Exit Loop If [Get(FoundCount) =0]

                                     Go to Layout [The First Layout]

                                  End Loop

                                  —note the two lines I have highlighted. Some issues:

                                  1.     The Go to Layout step will NOT be performed if no records are found, so you will be left on the layout navigated to in the first line inside the loop. Is that what you intend? If "The First Layout" is meant to be some other layout it won't happen, but if it is meant to be the same, then why have it since it is performed at the top of the loop already if you don't exit the loop, and if you do nothing has happened to change layouts?

                                  2.     If there is one or more records found at the top of the loop, what will now trigger exiting the loop? As far as I can see, nothing, since your only exit condition is none found.

                                  You say: "I am not convinced it is a scripting issue"; well I am.

                                  • 14. Re: Loops continuing to loop
                                    GSalmson

                                    Yes I can see that an else step would work there too. I will try that one out as well.

                                    1 2 Previous Next