8 Replies Latest reply on Feb 24, 2017 9:01 AM by CamelCase_data

    How to detect when a loop fails?

    kurt.bleicken

      A script loops through as many as 400 contact records and sends an email using the send mail script step with a one second pause. This was recently executed by one of our client users on WebDirect. The procedure failed about halfway through and the script apparently just stopped at a particular record.

       

      On a second attempt it failed again later at that same record. The email addresses for that record and the following record were valid. What would cause the script to simply stop at a particular record. Could that record, or the next record have been corrupted in some way?

       

      What is the best way for us, the developers, to get notified when a script in use by a client fails?

        • 1. Re: How to detect when a loop fails?
          CamelCase_data

          Are you familiar with the Get ( LastError ) function?

          A simple approach would be to have a script step

          Exit Loop If [ Get ( LastError ) ≠ 0 ]

          right after the Send Mail script step.

           

          You'll probably also want to add logging and reporting of errors, in which you could set the error code and other relevant information to variables/fields before exiting the loop. After the loop, you'll want to check against the errors logged, and take the appropriate action if an error was detected.

          • 2. Re: How to detect when a loop fails?
            siplus

            Maybe your provider considers sending more than 200 mails with 1 sec. interval as spamming ?

            • 3. Re: How to detect when a loop fails?
              kurt.bleicken

              I am familiar with the Get ( LastError ) function. And we do have an error log. If there is an email error, the script goes on to the next record. This is what we want it to do.

               

              What I'm asking is a little different. In this case the loop simply failed half way through the 400 odd records. We didn't find out until the client told us that several recipients hadn't received their emails.

              • 4. Re: How to detect when a loop fails?
                mikebeargie

                Are you running it as perform script on server?

                 

                Loop scripts on WebDirect are somewhat flaky in nature depending on what you are trying to do, as the server is trying to evaluate the context from the user, process the action, return the result of the action to the user, and then repeat ad nauseum through the loop.

                 

                From what I've found, to no fault of filemaker, is that the timing in fast repetitive loops can sometimes get thrown off (EG new action starting before old one finishes), causing the server and client to fall out of sync and the script to fail for no reason.

                 

                Thus, any loop based data processing I always perform as PSoS so that the server takes care of the whole thing, and only returns results to the user.

                 

                BTW, Siplus's advice is sound, you should be using an email service like Mandrill or 360works CloudEmail rather than the send mail script step. Something that's designed to handle emails in volume.

                • 5. Re: How to detect when a loop fails?
                  kurt.bleicken

                  That is possible, but I tested it with a dummy account sending to 400 records with no failures. We are sending out of a Google business account.

                  • 6. Re: How to detect when a loop fails?
                    kurt.bleicken

                    Thanks MIke, I'll check out CloudMail and Mandrill.

                     

                    But still the question, if the loop just stops how can I notify myself of that failure?

                    • 7. Re: How to detect when a loop fails?
                      DavidJondreau

                      I don't think you're hitting the limit in this particular case, but depending on the type of Google business account, there are limits to the number of e-mails you can send per day. But hitting that does trigger an error, 1506 if I recall correctly.

                      • 8. Re: How to detect when a loop fails?
                        CamelCase_data

                        If you have an error log, what are the error codes you are getting?

                         

                        Do you report these errors to the user (or yourself) at the end of the script? That might be a good idea to avoid issues like these going unnoticed for a long time.

                         

                        Do you validate e-mail addresses entered?