Save Records as PDF
just attach the email in the send mail script step instead of having it open as part of the save records as PDF script step.
and pause script has the option for pausing a specified amount of time so you can specify a pause of a few seconds or even a fraction of a second to make sure that the file is ready to attach without the user having to resume the script.
FileMaker runs script steps sequentially so if the "Save as PDF" script step and the "Send Mail" script step are in the same script then the file should be there before the send mail script step executes. Are you sure that there isn't an issue with the filename, filepath, or some other issue that is preventing file creation? Is the file actually even created at all in the file system?
FileMaker runs script steps sequentially
True, but a script can spawn processes that proceed asynchronously and then move immediately to the next step in the script. The process of printing a document or generating a PDF is one of them.
This is not the first time that I've seen this issue arise. Depending on the size and complexity of the PDF to produce a pause of just a few seconds is usually enough to resolve the issue.
Roughly speaking the script works fine 95% of the time creates the the PDF and attaches it to the email ready to send but the other 5% the PDF doesn't attach nor does it ever get created, I've assumed that the creation step was interrupted by the email step perhaps this is incorrect though? It also appears to be completely random, and because it's so infrequent it can take some time to recreate the issue. I'll add a pause and see if that solves the problem.
I think philmodjunk has hit the nail on the head here. You need a brief pause in the script between creation of the PDF and sending it as an email attachment. This is to give the OS time to update its indexing and therefore be able to locate the PDF file. Remember that Send Mail is engaging external programs, so OS indexing is needed.
But the PDF should be created even if too late to attach it. Normally, a file creation error, however, produces an error message even if you try to supress it with set error capture.
Is this a script that is being performed server side via a schedule or something?
Are you creating the PDF in your temporary folder?
A word to the wise...
When inserting the PauseScript step...go to each of your stations where you use this script and check it.
Computers work and communicate at different speeds.
One one of my resizing scripts runs between client and cloud...on my computer, no delay is needed when hardwired to network. On a coworker's, it needs a 0.1sec pause. Through Wifi it needs 0.5sec at work and 1.1 sec at home.
Keep the variability of delay in mind when setting your pauses...