6 Replies Latest reply on Aug 19, 2011 8:49 AM by Kat11_1

    Script generates duplicate e-mails

    Kat11_1

      Title

      Script generates duplicate e-mails

      Post

      I have a script that uses the Loop function to go through the list of found records and generate an e-mail with an attached file for each of the found records.

      For some mysterios, to me, reason it always generates two e-mails for each record. I checked that the check box to open an e-mail is not checked on the Save Records command. Hard as I look I can't see why the screept seems to go twice through each record. As always your help will be very much appreciated!

      Screen_shot_2011-08-18_at_3.14.22_PM.png

        • 1. Re: Script generates duplicate e-mails
          philmodjunk

          It looks to me like your script will send one email for each lineitem record in a customer's bill--which could be quite a few more than 2 times for each customer.

          It looks to me like your script should loop through a found set of records in the Bills table rather than the line items table. That way, you send out one email for each bill instead of one email for each line item record.

          PS. If you don't have FileMaker Advanced, you should get one as soon as possible. If you do, you should test a script like this with the debugger enabled so that you can step through the script on line at a time and see what happens. Not only does that save a lot of time figuring out what went wrong, it can catch situations where a layout based script trigger might interfer with the currently executing script.

          • 2. Re: Script generates duplicate e-mails
            Kat11_1

            Yes of course, my test sample has two line items per bill. And changing the table took care of this problem. Thank you!

            There is another thing that started to happen and I can't seem to figure out why. When I first started working on this script every e-mail had the file attached now not all of the e-mails get the file attached. I haven't changed anything on the Save Records as PDF nor Send Mail. And it appears to me that it happens at random. i know that is not the case but I don't know where else to look.

            FileMaker Advanced is top on my wish list. Thanks for your note on that too!

            • 3. Re: Script generates duplicate e-mails
              philmodjunk

              Not sure. If you don't have Advanced to step through the script and watch what happens, you might try putting a pause/resume right before the save as PDF step and maybe a show custom dialog step with the $Path Variable in the dialog right after the set variable step that computes it. I'd guess that the problem occurs either because there are no records to save as the PDF or that the file path is not valid...

              • 4. Re: Script generates duplicate e-mails
                Kat11_1

                When I put a Pause/Resume Script and look at the $BillFilePath variable (which was set to give the same name (MonthlyInvoice) to each bill record and thus write over the previus for this purpuse) before resuming the script  and the file got attached every time.

                When I removed the Pause/Resume Script file did not get attached for some records again. Restared the mail client, and computer with the same result.

                When I modify the $BillFilePath variable to save each record with a unique file name (as per the BillFilePath field in the Bills table). Every e-mail gets the file attached when the script runs without pausing. This would be a work around as now I have a number of files on clients' desktops that need to be deleted.

                • 5. Re: Script generates duplicate e-mails
                  philmodjunk

                  When you compute the filepath, you can use Get ( TemporaryPath ) to save the PDF to the temporary items folder and then you won't clutter your hard drive with old PDF files.

                  • 6. Re: Script generates duplicate e-mails
                    Kat11_1

                    I was hoping you will have a suggestion. This will work, thank you!