1 2 3 Previous Next 39 Replies Latest reply on Jun 6, 2014 6:52 AM by sundown

    Wrong PDF file attached to Email



      Wrong PDF file attached to Email


           Phil guided me in setting up a script to email status letters to supervisors. These are mostly done on the Filemaker Remote network. (http://forums.filemaker.com/posts/baca172a24).

           I originally had problems with the PDF attachment sometimes being dropped from the email. I added a delay to slow down the loop and it has seemed to work. The problems only showed up from the remote locations, not on the host computer.

           Lately I have found that occasionally when we email multiple letters, the first client's email has the second client's PDF file attached to the email. The second & all following  client's emails have the correct file attached. So the first & second emails both have the second PDF file attached. This only happens occasionally and only when sending on the Remote network.

           I first had the script loop delayed by 0.3 seconds and have increased it to 0.5 seconds, but just saw it happen again. Always the second PDF file attached to both the first two emails. No problem when emailing one at a time.

           I have attached my script code for this email function in hopes you can suggest a fix. 


        • 1. Re: Wrong PDF file attached to Email

               I'm surprised that this even works for more than one PDF. I get an error when I use PDF to save a PDF to a file name that already exists and usually save PDF's to the temporary folder with an appended timestamp to make sure that each PDF file name is unique.

          • 2. Re: Wrong PDF file attached to Email

                 Thanks  Phil for your time & effort in testing this to respond. I thought I set it up according to your instructions back in the original posts in June. How do I do the temporary folder and append a time stamp?

                 I am attaching a screen shot of the contents of each of the 3 steps so you can see what I have wrong. Hope the attachment is clear. Really appreciate your help.


            • 3. Re: Wrong PDF file attached to Email

                   I don't know that you need to do that, I've just expressed surprise that it works without popping up an error message telling you that it couldn't create the PDF the first time that the script loops around and uses Save as PDF to create a second PDF of the same file name and location. This is more a note to myself to investigate further why that isn't happening for you than a suggestion that you need to change that.

                   If you want to save to temporary items, use Get ( TemporaryPath ) instead of Get Documents path.

                   And expression for the $path variable might be this:

                   Get ( TemporaryPath ) & "DWI_Failure_" & Substitute ( Get ( CurrentTimeStamp ) ; [":" ; "" ] ; ["/" ; "_" ] ) & ".PDF" ]

                   But I don't think that this will actually solve the problem here. It will just keep the wrong PDF from being attached--you'll get an error or no PDF attached if the PDF isn't yet accessible at the time your Send Mail step executes.

                   It can take time to generate the PDF and a remotely Hosted file can be much slower to respond to things so I would try, as an experiment, using a much longer pause of say 10 or more seconds to see if that consistently avoids the issue. If it does, you can try reducing the pause to see if that still works for you.

              • 4. Re: Wrong PDF file attached to Email

                     So you are saying the slow development of the PDF has the second record already selected before the PDF Merge Field completed the first?

                     I have been wondering why this only happens with the first record even when there are sometimes a dozen records in the loop? What makes the first record slower?

                     I will try the increased delay, but this only shows up very infrequently, so it will take some time to test. These emails I am monitoring to check for problems are being sent by my son at his remote location. Things such as his internet speed, maybe 2 workers on the remote file at the same time, etc., could be causing  this timing  change, so I might not see the problem on my host computer. 

                      I did not understand what the error was when you said " I get an error when I use PDF to save a PDF to a file name that already exists". I will try your suggestion and continue to monitor these emails with a longer pause. Anything else you think of I can try, please let me know.

                     Thank you for your help.

                • 5. Re: Wrong PDF file attached to Email

                       I have been wondering why this only happens with the first record

                       I would guess that first time around, FileMaker has to launch code for generating the PDF that then remains in memory for it to be used the next loop around.

                       When I do this type of script, saving a PDF with the name that matches the name and location of a file that already exists, I get an error message from FileMaker reporting that the file could not be created. It's very clear that you are not getting this error message. This is what I find to be surprising.

                       What version of FileMaker are you using and on what OS?

                  • 6. Re: Wrong PDF file attached to Email

                         I have the latest iMac with Mountain Lion with FM 11 as the host. I have a couple of G5 macs using FM 10 with Snow Leopard. A couple of other MacBook Pros (2 to 4 years old) with Mountain Lion using both FM 10 & 11. 

                         Your guess sounds logical. If the email was first formed with first record Merge Fields & held until a PDF was available to attach, & the PDF Field Merge was delayed until the second record was selected, this would cause this problem. Can you think of a way to change the script to allow for a longer pause of the first record only & have the PDF coding remain for the loop records? This would not delay the total email process as long.

                         I originally had been using 0.3 sec. pause after noting 0.1 sec looked like it worked. Recently increased the pause to 0.5 sec & had the one failure when I started this post. Have now increased the pause to 1.0 seconds & will continue to monitor the emails.

                         I will report back progress as I monitor the results with various pauses. 

                    • 7. Re: Wrong PDF file attached to Email

                           The amount of time that you pause can be a calculated value if you click the Specify button in the small dialog that pops up for specifying the amount of time to pause:

                           If ( Get (RecordNumber ) = 1 ; 1 ; 0.5 )

                      • 8. Re: Wrong PDF file attached to Email

                             Just an update on the outgoing PDF emails for the last couple of days.

                             I set the loop pause to 1.0 seconds & have been checking all outgoing emails from the remote location. looked like it was good until this afternoon. In a group of 6 emails, the first 2 records had the same PDF attachment, but this time it was the PDF for the first record. Don't know how to explain this one.

                             So I went from the first record having the second PDF attached to now having the second record having the first PDF attached.


                        • 9. Re: Wrong PDF file attached to Email

                               Something isn't adding up here and I haven't figured it out either. Your script is still saving to the documents folder?

                               If so, run this script and then open the documents folder. What do you find? A single PDF file or many PDF files?

                               And you are running this script using FileMaker Pro and not FileMaker GO on an iPhone or iPad?

                          • 10. Re: Wrong PDF file attached to Email

                                 I am using FM Pro 11. The remote is FM Pro 10 used by my son at his place of business.

                                 I checked my document folder & it retains a single PDF file for each group run, retaining the last PDF file sent.

                                 I will have to wait until I can go to his place to check his Document folder. maybe this weekend.

                            • 11. Re: Wrong PDF file attached to Email

                                   The PDF's will be in the client's folder, not the host's

                                   The only other explanation that comes to mind here is that somehow your script is saving the wrong PDF from the wrong record in the instances where the wrong PDF ends up attached to the email..

                              • 12. Re: Wrong PDF file attached to Email

                                      The failure is on my son's laptop at his office, so I need to check his document folder this weekend. Is it correct that one PDF file is left in the document folder each time a single record email or a series of records are mailed? this is what I see on my host computer? What could cause his computer to be any different? And  i guess these files in the Document folder have to be manually deleted?

                                     Do you see  anything in my script  that would cause it to save the wrong record?

                                • 13. Re: Wrong PDF file attached to Email

                                       I missed your point on the Document folder until I sent some PDFs to myself & saw what you meant. I need to explain how I look for the wrong PDF file on an email. It is when the Merge field name in the PDF letter does not match the merge name in the email subject for the SENT mail. 

                                       My son uses a Macbook pro with FM Pro 10 at his remote location. Most of the emails are from that computer on a .Mac mail account. After we received a couple of replies (over several months)  that we had sent the wrong letter, I started monitoring his SENT mail on iCloud. Each outgoing email has the record's name merged in the subject & also in the PDF letter. All I have to do is click on each sent mail & see if the name in the email's subject is the same as in the PDF letter. This is where i see the problem when the names are not the same. The name merge in the email subject is always correct. 

                                       Hope this narrows down where the error is occurring.  It always shows up in the Sent mail box on his computer. 


                                  • 14. Re: Wrong PDF file attached to Email

                                         Yes, but your script replaces each PDF it generates with the next PDF that it saves. By the time your script get's to the last email sent, the PDF for the first email sent no longer exists as it has been replaced by subsequent PDF files. The only way that the last Email could attach the first PDF is if either that PDF were saved again or if the script somehow accessed a PDF in a different location.


                                              All I have to do is click on each sent mail & see if the name in the email's subject is the same as in the PDF letter.

                                         Hmmm, I suggest that you actually download and open that attached PDF file. Maybe the file name is wrong, but the contents of the PDF are correct.

                                    1 2 3 Previous Next