Don't know about PHP, but Save as PDF is not a compatible script step for server side scripts. There's a compatibility drop down in the lower left corner of the script editor that you can use to check a script for compatible steps.
Thanks Phil, really appreciated.
That explains a lot and as I am not used to dealing with server queries in the database I have just learned something that would have saved me about 5 hours of troubleshooting.
The server compatibility greys out the 'save Records as PDF'
The next questions is, have you heard of any work arounds or plug ins to be able to trigger the Save to Pdf from the server?
Don't know if any plug ins are available, you'd have to do some web searching, but a robot file can run non server compatible scripts from a client context and do so on a regular schedule. That might be an option for this here.
I may have solved the issue writing my reply, sorry to ask but can you direct me to a link or info to set up a robot file?
The functionality I am after is the person fills out a rather detailed on-line form as part of an e-learning course. When they finish they can ask for the formatted results to be emailed to them for inclusion in another paper document (as the Learning Management System does not have this functionality). This requires the script and save to pdf to be specific to their recordID.
Ahhh ... I may be able to work around this by storing the record ID's in the robot file as a record and the scheduled scripting saves each file to pdf and email the document then deletes the record. If I set up the scheduled script to first check if there are any records and exit if not it should not bog down the system much.
but one glitch: It is not working with SMPT as it will only send to one email address, I have to use an email client to send all emails. Any solution greatly appreciated.
Reading posts there has always been a to of angst trying to get Save to PDF to work from a server and then email. This is the solution.
Firstly Save to PDF does not work on server side script as pointed out by Phil above and I used his work on scripting from another post at http://forums.filemaker.com/posts/8046f20b65?commentId=177285#177285.
Another unrelated post says this is because Filemaker server has not purchased the license for this,(but Filemaker Pro has).
Some workarounds have a separate robot file which logs in to the main database and then that triggers a script in FMPro and Save to PDF occurs. If I have to have a file permanently open to enable client side scripting I may as well have the main file open (requires a FMProp license on the server which I have anyway) and run the timing scripts (below) internally.
1/ Create new table called PrintPDFCP, it has two fields, Record ID, ClientID - the Client ID is the relationship field
2/ Script triggered from the browser (our php in the first post above)
Set Variable [ $RecordID; Value:Get(RecordID) ]
Set Variable [ $ClientID; Value:Customerprofile::ClientID ]
Go to Layout [ “PrintpdfCP” (PrintpdfCP) ]
Set Field [ PrintpdfCP::ClientID; $ClientID ]
Set Field [ PrintpdfCP::recordID; $RecordID ]
3/ Make another script which will run a script periodically, in this case every 60 seconds while I am testing, I will put it out to 600 seconds when finished. This script step is:
Install OnTimer Script [ “printpdfCP”; Interval: 60 ]
4/ the printpdfCP script acts to
- find any records in the PrintPDFCP table, exit script if none found
- save records to pdf
- send emails with the pdf attached
- set recordID field to ""
- delete all records with RecordID=""
Thus is is quick if there are no records, and constantly cleans up the table printpdfCP so no accumulation of unwanted pdfs.
Go to Layout [ “PrintpdfCP” (PrintpdfCP) ] Enter Find Mode [ ]
Set Field [ PrintpdfCP::recordID; "> 0" ] Set Error Capture [ On ]
Perform Find [ ]
If [ Get ( FoundCount )>0 ]
Go to Record/Request/Page[ First ]
Set Variable [ $clientemail; Value:Clients::Email ]
Go to Related Record [ From table: “Customerprofile”; Using layout: “Customerprofile” (Customerprofile) ][ Show only related records ]
Save Records as PDF
Send Mail [ Send via E-mail Client; To: XXXXXX (attaching your pdf)
Go to Layout [ “PrintpdfCP” (PrintpdfCP) ] Go to Record/Request/Page
[ Next; Exit after last ]
Enter Find Mode [ Specified Find Requests: Find Records ] [ Restore ]
Set Field [ PrintpdfCP::recordID; "" ] Set Error Capture [ On ]
Perform Find [ ]
Delete All Records
[ No dialog ] Else
Exit Script [ ] End If
I suspect that Server is not allowed to save as PDF for the same reason that it is not allowed to Print. Both operations require interacting with another application (two actually in the case of save as PDF--a printer driver and the Adobe licensed code). If anything were to go wrong, it could cause major issues for your server that would be difficult to identify and resolve.
Both an SMTP mail server or an email client should be able to handle multiple email addresses specified for recipients.
The SMPT has got me stumped as why it will not do more than one email, using the script debugger the save to pdfs, the $variables are all being set correctly but SMPT will only send the first record when the email client will happlily send them all. At the moment I will let sleeping dogs lie and use the client.
It has taken a lot of time to figure out the stuff that is not told in the posts. I am writing it down here in case anyone else finds the post and needs the solution.
1/ the Install Run Timer needs to be triggered somehow in the window you want it to run. If it is not triggered it will not run by itself. Once triggered it keeps running until you leave the window or start another timer script.
2/ that is the reason for the Robot file as one window can stay open all the time. Set the window open script trigger to run the timer script
3/Make up an apple script to open the robot file, save as an application and add application to startup (or log in ) items.
4/ This solution needs a Filemaker Pro license to run.
By the way, have a good weekend
3) You can also set up an OS based scheduling utility such as windows task manager to open the file. This can even eliminate the need for Install OnTimer Script. I'm not a mac user but I've heard of something called "Chronos" (Kronos?) to do this on Mac systems.
Thanks Phil, your guidance is really appreciated.
The Apple script is just to make sure the robot file is opened if the computer re-starts, say after power failure.
Now I have the majority of the problem fixed I will let it run for a while and later I will write in the functionality of changing the install on timer duration (so as to send required documents immediately when a file is available to print) and then reinstate a default much longer duration so I don't have it triggering constantly. 12 hours tracking down and solving this problem is enough time away from eh main game for now :0) PHEW!