Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

emailing a PDF form from FM 9


This topic is 4214 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello,

I have read back through the answers already given, but I am still having a hard time scripting this simple task.

I am trying to create a PDF document, with the file name being PO:Approval & ".pdf". I am saving that file to a folder on the desktop. In saving the PDF, I can create an email with said file as an attachment, but I have to go back and fill in all the fields of the email.

If I try and use the Send Email script step, I can't figure out how to attach the file I just created. It seems that the "Attach File" parameter is looking for a specific file.

What am I missing here? Since I want to send both Purchase Orders and Requisitions, I would like to be able to script the email subject accordingly.

Thanks for any help,

Tony

Posted

Here's a demo that sends an Invoice as a pdf. As you'll see, I don't use the attach to email option in the Save as PDF. I also set a variable to the file path and use it in the Save as PDF and the Email Attachment.

You've mentioned that you save the PDFs in a folder on the desktop, so you'll need to adjust the path. You could use Get (TemporaryPath) in place of Get (DesktopPath), so that the pdfs get written to the OS' temporary folder, which is emptied by the OS periodically.

InvoiceDemo.fp7.zip

  • Like 2
Posted

Thank you! It's amazing how a little syntax typing error makes a big difference!

I am amazed at the wealth of information on this forum.

Tony

  • 1 month later...
  • 3 months later...
Posted (edited)

Hi Bcooney.

So i use this and it saves it to the Documents folder but what is the syntax to save it in an "invoice folder with in the "Documents folder"

Get (DocumentsPath) & "Inv" & INV:;)__kP_INV_ID & ".pdf"

i did try this

Get (DocumentsPath/[color:red]invoice) & "Inv" & INV::)__kP_INV_ID & ".pdf"

but it did not work.

Thnks

RT

Edited by Guest
Posted

Get (DocumentsPath/invoice) & "Inv" & INV:;)__kP_INV_ID & ".pdf"

Try...

Get (DocumentsPath) & "Invoice/" & "Inv" & INV::)__kP_INV_ID & ".pdf"

Try studying a little about string concatenation and file path references.

Posted

thank you so much it works, will read up more about the subject.

  • 1 year later...
Posted

This is a great example file. Is there anyway to have the email attach both the PDF that the "Email INV pdf" script does, and another standard PDF with terms of order, that will not change for each record?

Thanks

Adam

Posted (edited)

Only one attachment is supported with FM. To have more than one attachment or to send html email, you need an email plugin.

Another thought, couldn't the terms of order be in the footer or a trailing grand summary part (ie part of the same PDF)?

Edited by Guest
  • 11 months later...
Posted

I imported this script into my database, ran it and it pulled up my email program, started a new message and just has the file $exportPath attached. What part of the script do I need to change to attach my .pdf file?

Thanks

Posted

You'd have to change several things. How about posting your script (just print it to pdf or do a screen shot)? Or, post your file (zipped).

  • 1 year later...
  • Newbies
Posted

I have been able to write the script to save my PDF to a variable name, but it won't attach the file to an email.  This is what my script looks like:

 

 Set Variable [$filePath; Value:Foodler::FilePath & ".pdf"]

Save Records as PDF [Restore; No dialog; "$filePath"; Records being browsed]

Sen Mail [send via E-mail Client; To: DAHSEDmaster::Send statement to:; Subject: "DASHED Statement Attached"; Message: "Your latest statement is attached."; "$filePath"]

 

This script will save the PDF, as requested, pull up the send email window and populate the email address, but there is no PDF file attached...what am I missing?

 

Thanks,

Posted

You're missing a correct path. Please print your script to PDF and post here. You've typed in your script, but that's not as accurate as the real script. More specifically, what does $filePath equal after the first script step?

  • Newbies
Posted

I've attached the PDF of my script...

 

When I run this, it saves the PDF file into my directory as follows:

 

filemac:/My Book/OAS/Clients/Dash Deliveries LLC/RP PAYOUTS/FM TEST/$filePath

 

$filePath ends up being the name of the file that I've designated as a new field in my db to be the Name & ID & Period Date.

 

Thanks for your help,

AmberScript.pdf

Posted

I think you're getting ahead of yourself. How about simply using setting $filePath to Get (DesktopPath) & "myDoc.pdf" and see if it works? You're trying to store a path in a field..and I cannot tell if the script is in the correct context to grab that field's value. What is the value in Foolder::FilePath? Beware of extra periods in a file name or dashes, especially if you're grabbing a date value.

  • Newbies
Posted

It wouldn't surprise me if I'm getting ahead of myself!  :-)  Basically, since I wanted the PDF file name to contain all the identifying information I needed, I created a text field.  For example, the file name that gets saved to the drive location is Veggie Fun12506__03_04_03_10.pdf  This file name and field is a text calc field of Restaurant Name & Restaurant ID & Period (where Period is a text field as opposed to a date field).

 

I'm just not sure why the script can save the file, but not attach said file to an email.

Posted

I would like $filePath to equal the complete path. It seems to me that your Save Records as PDF is a concatenation of a prefix and $filePath. Is that correct? Also, try the simple path like I use in the demo.

  • Newbies
Posted

HA!  I got it, thank you!  I think I had different paths between my Save as PDF and Send Mail scripts....I love it when a good script comes together!  Thank you so much for your help!

  • 3 weeks later...
Posted

Here's a demo that sends an Invoice as a pdf. As you'll see, I don't use the attach to email option in the Save as PDF. I also set a variable to the file path and use it in the Save as PDF and the Email Attachment.

You've mentioned that you save the PDFs in a folder on the desktop, so you'll need to adjust the path. You could use Get (TemporaryPath) in place of Get (DesktopPath), so that the pdfs get written to the OS' temporary folder, which is emptied by the OS periodically.

 

Thanks for the great demo file, has helped a heap!

 

I have a couple questions on customizing this script and would really appreciate some help with...

 

 1) I would like to have .pdf file name include the current date but haveing troubles getting script to accept it, i.e. Get (DesktopPath) & "Inv" & INV::__kP_INV_ID & " & Get (CurrentDate) & ".pdf" NOTE: I would like date formatted as 2013-04-23 w/zeros

 

 2) DesktopPath and TemporaryPath are great and powerful, but I would like to store all emailed .pdf's on our server. My question is not how to set up the path, tho a tip may be helpful here, but to include in the script some sort of parameter check that confirms user is connected to the server and if not connects or notifies. Preferably connects (May just set up PC's to connect to server on start up). But still need to have some sort of error capture.

The problem I'm having is; if User is not connected to the server the script will not properly save file.

 

:thumbsup: Thanks in advance for any help on this!!!

Posted

Get(CurrentDate) will return the date with slashes.  In a URL those are interpreted as directories.  

You need to spell out your date :

$FormatDate = 

Let(

cd = Get(CurrentDate);

Year(cd) & "-" & Right("0" & Month(cd);2) & "-" & Right("0" & Day(cd);2)

)

 

Then your path would be

Get (DesktopPath) & "Inv/" & INV::__kP_INV_ID  & $FormatDate & ".pdf"

 

(assuming that you want the files in a directory on your desktop named "inv")

 

 

I can't help you with your #2.  Sorry.

Posted

@Dr Evil

 

You were asking how to test whether a user is connected to a server or not.  One approach would be to have a small test file kept permanently at a specific path on the server and then attempt to import this file; if the import works, you know they have a connection, if it doesn't, then you can assume there is a problem.

 

The 'import' process can be as simple as inserting a text file with a few characters in it into a global field.

 

HTH

 

Brian

Posted

$FormatDate = 

Let(

cd = Get(CurrentDate);

Year(cd) & "-" & Right("0" & Month(cd);2) & "-" & Right("0" & Day(cd);2)

)

 

As mentioned before, this is perfect! Tho can we take it just a bit further?..

 

 

Does (CurrentDate) carry current time too? Can we simply further break out the formatting of the current date?

Can you show me what the code would look like for this?

 

I will be saving these .pdf files to a server in effort to track report history. So "save over" or "append" .pdf is not ideal.

So each .pdf file saved will have to include a unique name, maybe utilize the current time, i.e. 1234-PurchaseOrder_2013-04-24_02-16-58

 

I'm open to suggestions here, how to write out the time, alternative unique identifiers, etc...

 

Thanks again for all the help here on FM Forums!

Posted

Does (CurrentDate) carry current time too? Can we simply further break out the formatting of the current date?

Can you show me what the code would look like for this?

 

No, but Get(CurrentTimestamp) does.  You would use the same format as above, along with the Hour(), Minute(), and Second() functions.  Insert the desired separators as literal text the same way as in my example.  You would also use the Right("0" & <data>; 2) construct to output the leading zeros.

Posted

:thumbsup: BOOM! Works great.

 

Even tho it works, I don't fully understand some of the code.

 

In your formatting code you use the Let function along with cd =

I figured cd means CurrentDate, I did not change this for the Timestamp and still worked so I assume its developers prerogative to label as seen fit, intuitive and consistent?

Posted

The 'import' process can be as simple as inserting a text file with a few characters in it into a global field.

 

I think I got this to work the way you suggested. I've attached a screen shot and demo file of what I did.

Thanks for your help!!! Would not mind any further clean up help on this if you are inclined. 

post-80154-0-38451200-1366855722_thumb.p

demo_sever_connect.fp7.zip

Posted

:thumbsup: BOOM! Works great.

 

Even tho it works, I don't fully understand some of the code.

 

In your formatting code you use the Let function along with cd =

I figured cd means CurrentDate, I did not change this for the Timestamp and still worked so I assume its developers prerogative to label as seen fit, intuitive and consistent?

 

cd is just a variable name.  In a Let() statement, variable names don't need a $ or $$ in front.  I used the Let() and a variable name because it makes the calculation much easier to read and follow than repeating Get(CurrentDate) a half dozen times. The variable is not stored; it only lasts for as long as it takes to get the result of the calculation.

 

  • Like 1
Posted

doughemi... Thank you for taking the time to help me on this project and for the Let/variable explanation!

:yourock:

Posted

@DrEvil

 

Your script should work OK.  If you use the Insert File statement, you only need a single global field and don't have to manage the table into which portal_creation_control.fp7 is being imported.

 

Brian

Posted

Hi Brian, initially I tried to use Insert File, but I could not figure out how to get it to work without dialog.

The Import Records has a check box to "perform without dialog" to avoid this dialog problem.

the portal_creation_control.fp7 was just some random file i used for testing.

 

Can you help me figure out how to use the the Insert File without dialog issue?

I've made some adjustments in attached demo file to match your instructions.

 

THANKS! :)

demo_server_connect_02.fp7.zip

post-80154-0-26022100-1366907944_thumb.p

Posted

To use the insert file script step, the Demo::Container field you specify must be on the current layout.  Instead of the file name, put the full path to the server into a variable called (say) $filePath and specify $path as the source file

 

I suggest that you set up a blank layout based on the demo table, and add the field container to that layout -  lets call the layout ServerCheck -  your script would now look like this:

 

Set Error Capture [On]

Set Variable($filepath; <insert path to the server>  & "arrow_right.png"]
Go to Layout ["ServerCheck" (demo)]
Insert File [demo::container; "$filePath"]

If [Get(LastError) ≥ 1]
   Show Custom Dialog["Oops";"You are not connected to the server"]
   Go to Layout [original layout]
   Halt Script
Else
   Show Custom Dialog["GREAT";"You ARE connected to the server"]
End If
Go to Layout [original layout]
 

One other point, if you want this to happen automatically for your users, then they will all have to have the same path to the server

 

HTH

 

Brian

Posted

Hello Brian,

 

I must be missing something. I've made your suggested and minor changes to the script, set variable / go to layout / etc.

 

Tho these changes did not seem to address the issue of FileMaker bringing up a dialog asking where file is to insert when User is NOT connected to server. The script works fine when User is connected to server, insert is successful with no dialog windows.

 

What am I doing wrong?

Thanks for helping me with this!

post-80154-0-70143900-1367513055_thumb.p

Posted

Hmmm, yes your're right -  my bad.  You can't suppress the dialog box on the Insert text script step if the file is not present, but you can with the Import Records step.  Sorry, I've been wasting your time on that idea.

 

If you're using the Import records technique, I suggest that you delete the imported record(s) after a successful import just to keep the table from growing to any size.

 

Brian

This topic is 4214 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.