MsqedMan Posted March 21, 2009 Posted March 21, 2009 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
bcooney Posted March 21, 2009 Posted March 21, 2009 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 2
MsqedMan Posted March 21, 2009 Author Posted March 21, 2009 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
hollyheadhunter Posted May 1, 2009 Posted May 1, 2009 bocoony - i've also been trying to figure this out for months. thank you so much for the example!
RT Posted September 1, 2009 Posted September 1, 2009 (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 September 1, 2009 by Guest
IdealData Posted September 1, 2009 Posted September 1, 2009 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.
RT Posted September 1, 2009 Posted September 1, 2009 thank you so much it works, will read up more about the subject.
adamworking Posted October 12, 2010 Posted October 12, 2010 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
bcooney Posted October 12, 2010 Posted October 12, 2010 (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 October 12, 2010 by Guest
Matthew R White Posted September 12, 2011 Posted September 12, 2011 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
bcooney Posted September 12, 2011 Posted September 12, 2011 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).
Newbies amberolivieri Posted April 1, 2013 Newbies Posted April 1, 2013 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,
bcooney Posted April 1, 2013 Posted April 1, 2013 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 amberolivieri Posted April 1, 2013 Newbies Posted April 1, 2013 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
bcooney Posted April 1, 2013 Posted April 1, 2013 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 amberolivieri Posted April 1, 2013 Newbies Posted April 1, 2013 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.
bcooney Posted April 2, 2013 Posted April 2, 2013 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 amberolivieri Posted April 3, 2013 Newbies Posted April 3, 2013 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!
Dr. Evil Posted April 23, 2013 Posted April 23, 2013 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. Thanks in advance for any help on this!!!
doughemi Posted April 24, 2013 Posted April 24, 2013 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.
brian rich Posted April 24, 2013 Posted April 24, 2013 @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
Dr. Evil Posted April 24, 2013 Posted April 24, 2013 $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!
doughemi Posted April 25, 2013 Posted April 25, 2013 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.
Dr. Evil Posted April 25, 2013 Posted April 25, 2013 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?
Dr. Evil Posted April 25, 2013 Posted April 25, 2013 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. demo_sever_connect.fp7.zip
doughemi Posted April 25, 2013 Posted April 25, 2013 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. 1
Dr. Evil Posted April 25, 2013 Posted April 25, 2013 doughemi... Thank you for taking the time to help me on this project and for the Let/variable explanation!
brian rich Posted April 25, 2013 Posted April 25, 2013 @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
Dr. Evil Posted April 25, 2013 Posted April 25, 2013 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
brian rich Posted May 2, 2013 Posted May 2, 2013 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
Dr. Evil Posted May 2, 2013 Posted May 2, 2013 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!
brian rich Posted May 3, 2013 Posted May 3, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now