9 Replies Latest reply on Feb 22, 2015 2:10 PM by pvh

    Save to Pdf does not work from external triggers (php or run from server)

    pvh

      Title

      Save to Pdf does not work from external triggers (php or run from server)

      Post

      Using FM13, Mac and php

      I have a script which saves the layout as a pdf, sets up an email, attaches the pdf and sends via smpt.

      It works just fine when triggered inside Filemaker 13 e.g. 'run script'

      HOWEVER: we are calling the script through a web page

      $recid = $Customerprofile->getRecordId();
          $editCommand = $this->fmDb->newEditCommand('Customerprofile', $recid);
          $editCommand->setScript('printtopdfcustomerprofile', $recid);
          $editCommand->setField('timestampclientprofile', time());
          $result = $editCommand->execute();

      The script is triggered OK  and everything works EXCEPT it will not save the pdf file so nothing gets attached to the email.  

      Note: If there is a file of the right name in the location designated the file attachment to the email works OK 

      I have also trialled setting up the script to run externally on the server and this gives exactly the same results... the save to pdf does not work. I have used the script debugger on the perform on server script but it will not swap over to the script when it transfers to the server so I cannot see what error is happening with the save to PDF.

      Obviously there is an issue on triggering this functionality from outside FM13 . I can find hints that it does not work and all the plugins I have checked out do not mention that they are addressing this specific issue. 

      i have considered doing work arounds but all field and layout scripts are triggered when they are 'active' which is no good when accessing the database through the server. 

      Does anyone know a work around or plug in that will allow us to get FM13 to save to PDF when triggered from outside of FM13?


       

       

       

        • 1. Re: Save to Pdf does not work from external triggers (php or run from server)
          philmodjunk

          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.

          • 2. Re: Save to Pdf does not work from external triggers (php or run from server)
            pvh

            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?

             

            • 3. Re: Save to Pdf does not work from external triggers (php or run from server)
              philmodjunk

              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.

              • 4. Re: Save to Pdf does not work from external triggers (php or run from server)
                pvh

                Hi Phil

                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.

                 

                 

                 

                • 5. Re: Save to Pdf does not work from external triggers (php or run from server)
                  pvh

                   SOLUTION

                  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) ]
                  New Record/Request
                  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.

                  Script below.

                  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 ]

                  Loop

                  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 ]

                  End Loop

                  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 

                   

                  • 6. Re: Save to Pdf does not work from external triggers (php or run from server)
                    philmodjunk

                    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.

                    • 7. Re: Save to Pdf does not work from external triggers (php or run from server)
                      pvh

                       

                      Thanks Phil,
                      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

                       

                      • 8. Re: Save to Pdf does not work from external triggers (php or run from server)
                        philmodjunk

                        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.

                        • 9. Re: Save to Pdf does not work from external triggers (php or run from server)
                          pvh

                          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!