Jump to content
Per Waagø

Send mail with variable PDF

Recommended Posts

Per Waagø    0

Hi Forum! 

I have a script which sends an email to [current record] . Now I want to attach a PDF to the email automatically using the script.

So far I have tried with ... filewin:/$driveLetter/$targetDir/$[name_of_unique_field_from_FM]  as variable file path. But nothing is attached when I run the script. 

I hope you can help. 

Edited by Per Waagø

Share this post


Link to post
Share on other sites
Wim Decorte    446

The window where you specify the path to the attachment is not a calc window so you can not mix strings and variables.

It can take a variable but only the variable, so the variable has to contain the full path and file name.

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Per Waagø    0

Hi there!

 

Thank you for your quick answer!

I am not sure I totally have made my problem clear. I dont believe I am using a calculation. 

Right now I have specified the attached file as:

filewin://GCteam/Shared Documents/John Smith.pdf

Where John Smith in this case is the [name_of_unique_field_from_FM]. That name of course varies from record to record.

So are you saying that it is not possible to make the path relative? 

 

 

 

Share this post


Link to post
Share on other sites
Wim Decorte    446

Yes you can but not like this:

filewin://GCteam/Shared Documents/$someVariable

In your script use Set Variable to set $someVariable to "filewin://GCteam/Shared Documents/[name_of_unique_field_from_FM].pdf"

Then in the window where you specify the attachment, just use:

$someVariable

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Smiley    0

Hi tried to send out email with variable pdf.however i get the attached error messageScreenshot.jpg.c598f5834c9d1fc3cd4cc6a96

 

 

My script is as follows

Screenshot.jpg.f42952b2d29fd3dc77eec215a

 

Any idea where i am going wrong and what is causing this error.

 

p.s THe button is on the record i ewant to attach

Share this post


Link to post
Share on other sites
bcooney    101

Can't see the full script step, but do not use . in a table occurrence name, but rather an underscore.

Share this post


Link to post
Share on other sites
steveald    0

I'm having somewhat of the same issue.

bcooney, your demo from 2009 (http://fmforums.com/forum/topic/65699-emailing-a-pdf-form-from-fm-9/?p=311349) helped a great deal. But I can't seem to get the email attachment filepath right.

The purpose of my script is to:

1) go to each record in the database

2) save the layout for the current record as a pdf in a folder on my desktop - that pdf will have a filename derived from record data

3) send the pdf file in an email addressed using record data

4) go to the next record and repeat the process until all records have been processed

Everything works except there is no attachment in the email that is sent. Here is my script. What am I missing?

Screen Shot 2016-07-08 at 10.14.55 AM.jpg

Edited by steveald

Share this post


Link to post
Share on other sites
bcooney    101

Use Get (DesktopPath) & "Files/" &  KCL Master PrePrint::Combined Employee Name & ".pdf"

Just a suggestion, spaces are not your friend. Use underscores in table and field names.

Share this post


Link to post
Share on other sites
steveald    0

No joy. Still no attachment in the email.

Do I need to specify different paths for saving the file and then for retrieving it to email?

Here is the script after making the changes you suggested (assuming I did it right).

 

Screen Shot 2016-07-08 at 12.37.48 PM.jpg

Share this post


Link to post
Share on other sites
steveald    0

It looks like to key might be setting more variables. Thanks for the suggestion, BruceR. I'll give it a try first thing Monday.

Share this post


Link to post
Share on other sites
BruceR    152

"It looks like to key might be setting more variables."

It isn't strictly necessary. But sometimes it can help clarify your thinking about what chunk of code does what.

Share this post


Link to post
Share on other sites
steveald    0

No joy.

Thinking the mail process might need new variables other than the ones used to create the file in the first place, I came up with the following. But there is still no attachment in the sent email. My guess is the issue is somewhere in the path for where to get the file to attach to the email. I thought it might be because the file wasn't saved to the folder yet when the Send Mail command was invoked, but adding a Pause didn't help.

Also, can someone remind me what character is used within the Send Mail options to force carriage returns in the body of the email message?

Screen Shot 2016-07-11 at 9.09.19 AM.jpg

Ignore the last bit. Char(13) is what I was looking for.

Edited by steveald

Share this post


Link to post
Share on other sites
bcooney    101

What is the value of $filename? Does it contain a character that is causing the path to be invalid?

Share this post


Link to post
Share on other sites
steveald    0

You may be onto something. It's the first and last name of the intended recipient. With a SPACE in between! Let me replace that with an underscore and try again.

Share this post


Link to post
Share on other sites
steveald    0

No luck.

Even after I took it one step further. EmpCombinedNameNoSpace is the recipient's first and last name with nothing in between. So, an example of the name of the file saved to the folder would be "JohnSmith.pdf". Which means the path to the file should be /Users/Me/Desktop/Files/JohnSmith.pdf for both saving and sending the file.

Do the requirements for the path syntax for Send Mail differ from those for Save Records as PDF?

Here is my current script.

Screen Shot 2016-07-11 at 9.55.00 AM.jpg

Share this post


Link to post
Share on other sites
bcooney    101

No, creating the path is identical. Are you seeing pdfs in the Files folder? You could simply this by writing them directly to the desktop. I actually use Get (TemporaryPath) for this.

Share this post


Link to post
Share on other sites
steveald    0

My concern with that is, I will be applying this script to literally thousands of records. So I felt the folder was necessary.

Share this post


Link to post
Share on other sites
BruceR    152

Well, it appears that the thinking was not clarified.

You have established the full PDF path once. That's all you need.

script_mod.jpg

Share this post


Link to post
Share on other sites
steveald    0

That makes sense. But it looks like I'm back to the first revised script. And still no attachment in the sent email.

 

Screen Shot 2016-07-11 at 12.14.22 PM.jpg

Share this post


Link to post
Share on other sites
BruceR    152

Does the PDF get created?

Also, can you please stop posting screen shots and actually post your script? 

Share this post


Link to post
Share on other sites
BruceR    152

I wonder about adding a pause between save and send. Also, while testing, turn show dialog on for the send mail step.

Share this post


Link to post
Share on other sites
Lee Smith    144

Hi steveald,

On November 23, 2015 at 5:41 AM, Per Waagø said:

filewin://GCteam/Shared Documents/John Smith.pdf

It is so simple in 14 to do this. Select the script in the Workspace and the use the button at the top right. Copy to Text, and the paste the result in your Body of the post.

 

HowToUseCopyScrioptText.png

Share this post


Link to post
Share on other sites
steveald    0

Lee Smith, I don't see a Copy to Text button anywhere on my Script Workspace screen. Is it because I am using FMPA 15 now? Sorry, I forgot to update my Profile. (I was quite confused about this since your screenshot didn't appear at first for some reason. But that Copy Script Text button is not there in my Script Workspace.)

Sorry BruceR, I missed your screenshot comment.

I tried it with and without a 2 second pause again and With dialog On and Off. The pause had no effect. But the With dialog On resulted in the attachment appearing in the email as desired. So, it works - sort of.

My only concern with that is having to click Send on every email message that appears. And, as I mentioned, there will be thousands. Thoughts?

Edited by steveald

Share this post


Link to post
Share on other sites
Lee Smith    144

I don’t have version 15 so I can’t verify this. Perhaps they changed the button?

The old fashion way, is to print to Preview and then copy and paste that to your post.

Share this post


Link to post
Share on other sites
steveald    0

That's odd. I still had FMPA 14 on my computer, so I tried that - and still no Copy Script Text button. Print > Open PDF in Preview worked though:

Save Records to Folder 3

Go to Record/Request/Page

[ First ] Loop

Set Variable [ $fileName; Value:KCLMasterPrePrint::EmpCombinedNameNoSpace & ".pdf" ] Set Variable [ $folderPath; Value:Get (DesktopPath) & "Files/" & $fileName ]

Save Records as PDF [ File Name: “file:$folderPath”; Current record ]
[
Document - ]
[
Pages - Number Pages From: 1; Include: All pages ]
[
Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ]

[ Restore; No dialog ]

Send Mail [ Send via E-mail Client; To: KCLMasterPrePrint::EmpEmail; Subject: "Requested File"; Message: "Dear " & KCLMasterPrePrint::Emp First Name & "," & Char (13) & Char (13) & "Attached is your file." & Char (13) & Char (13) & "Thank you," & Char (13) & Char (13) & "Steve" & Char (13) & Char (13); Attachment: “file:$folderPath” ]

Go to Record/Request/Page

[ Next; Exit after last ] End Loop 

Share this post


Link to post
Share on other sites
BruceR    152

Many problems can be solved by having fewer customers.😀

Share this post


Link to post
Share on other sites
steveald    0

My company might disagree - from a staying-in-business perspective.

Does that mean that you believe the only way I can do this is with the dialog box appearing for each invocation of the Send Mail script step?

Share this post


Link to post
Share on other sites
BruceR    152

No. It was attempted humor.

But there is something going on here regarding ensuring that the PDF gets generated and cache flushed. Perhaps others will have some ideas.

Share this post


Link to post
Share on other sites
Lee Smith    144
47 minutes ago, steveald said:

 

That's odd. I still had FMPA 14 on my computer,

 

AFAIK, this is the same for both versions. I looked up a video on the new Script Workspace in 15 YouTube script workspace FileMaker 15 and it shows in the workspace still. If you are using FileMaker Pro Advance, then it should be in both. Not sure if it is different in client, or you have a problem with your setup.

One more thing. Do you have Admin access to this file?

Share this post


Link to post
Share on other sites
bcooney    101

“file:$folderPath” 

Looks like it's in quotes! Should simply be $folderPath.

Share this post


Link to post
Share on other sites

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


  • Who Viewed the Topic

    2 members have viewed this topic:
    amallison  docasar 
  • Similar Content

    • By pomilpetan
      Good morning everyone I created a database runtime solution with FileMaker Pro 15 advanced. The program must export the contents of a form in PDF format. In a solution that runs under FileMaker I could use the command "Save as PDF" but this command does not work in a runtime solution. Could someone tell me how I could make this function? thank you so much.
    • By docasar
      Hi,
      I have just downloaded the 360works Email plugin Sample and I am doing some tests to check whether this would solve my problem. I would like to be able to download all emails from my email account into "messages" table and then on each customer record show those emails which are related to that customer via a portal based on a relationship between, but what I can not figure out how to do it is that the portal would show but types of emails those marked as "from" emails and those marketd as "to" emails. So far I have created a relationship between Customers::email  ------- Messages::From and the portal would show all "from" messages. If I would set the relationship as Customers:email ------ Messages:To, the portal shows all "to" messages, but what I am trying to make is a join portal that would show by date both "from" and "to" messages, then I plan to make a Conditional Formating saying that if Customers:email = Messages::From then all text in blue, and all text in green when it is TO.
      Is this something that can be achieved?
      Thanks a lot for any tip,
      Luis
       
    • By FileDumb
      Hi everyone,
      I have done some research on this but cannot make headway so any help would be much appreciated!
      I am currently thus:
      • Using FM 13 pro advanced to create a runtime solution for use on Windows 7 PC
      • All well apart from when I go to a script to send an attachment by email... "email client not found" comes up...
      Tried setting the default email client but it doesn't show in default programs in Win 7
      Incidentally this system I created works ok in Mac! (but it won't be used on a Mac so...
      Many thanks in advance,
      FileDumb
    • By Peter Wagemans
      Yesterday, I tried to move a script that creates a PDF ( and mails it ) to a server side script, as the "save records as PDF" script step is now supported in server side scripts.
      It did not work correctly, and generated an error 800 (file could not be created on disk) in the server log. Rather generic error.
      I changed the script to point to a blank layout instead. No more error. A nice blank PDF was created.
      I put a text box with "test" in it on the layout, Arial 12 point. -> error 800
      I removed the text box and put a png graphic on the layout -> OK
      I put a text box in a font that I was sure of the server did not have -> OK!
      I tried this several times, 2 several fonts, and the results and errors were consistent. So if during the PDF creation, the server replaces the font reference by its own replacement font reference, it is able to save as PDF. If a reference lik "Arial" is used, it fails and the server reports the generic error that it can not create the file on disk (800).
      I'm using MacOS 10.12.4 as client and Window Server 2012R2 as the server. Maybe there is a cross platform issue here? As always, more testing is required.
      Can anyone confirm similar issues? Any workarounds that are known? Any thoughts and insights?
    • By Cable
      I have several reports that use Google Charts displayed through a web viewer to display a "'gas gauge" type of chart. This is a very popular style for our dashboard reports to the point where it is a requirement.
      I originally started using them in FileMaker 14 and they worked great. When FileMaker 15 came out they wouldn't work at first but then did after an update to the code.
      I'm now testing Filemaker 16 and they're back to not working properly.
      They do display on the screen just fine but if you try to print preview, print, or Send to PDF they do not show.
      Does anybody have experience with this or know if a setting changed in FMPA 16 that could be causing them to not print?
×

Important Information

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