send pdf after generation

I have a grid appication that the initial module selected is pdf generation.
within the OnScriptInit even I have the following code

sc_set_pdf_name = “contract_notifications.pdf”;

I set this because I want the generated file to be the same every generation.

I then use the sc_send_mail macro to email the pdf to a email address(s)

If I run the application then if there is no file already in the directory (_lib/tmp)
then it fails.
If I comment out the send mail attachment and the file generates then the when I remove the comments
it send the email, but it is always a generation behind.

I tried putting a sleep(30) statement after the sc_set_pdf_name line to make it finish.

All I am trying to figure out is how to send the pdf generated by the application…

Kevin Driscoll