1 2 Previous Next 19 Replies Latest reply on Aug 17, 2015 9:28 AM by Jason_Farnsworth

    Server Side Scripting


      Server side scripting is a bit of an emigma too me at the moment and I am hoping for a bit of clarity with this discussion.


      At the moment the ultimate task that I am attempting to perform is sending emails of reports (pdfs) created and dumped on the server (via a client script) from the server as that is all I can get IT to give me.

      So the details

      I have a script that I run to create the report (pdf) and I save it to the Server disk space.


      I have to send the email from the server as IT is blocking the port from my PC as such it has to go via SMTP. (The server is sending emails just fine)

      In the process I thought I would pass the details of where to find the file as well what it was named via variables $$ ha then I re-vistited Greg's Devcon presentation and noticed I lose the use of variable in the pass to server.

      How are details as such typically handed in this type of script call?

      I have a copy of Filemaker Pro installed on the server is it possible to somehow trigger that copy to do what I need?



        • 1. Re: Server Side Scripting



          Lots of questions here - and first off if you are looking to use Perform Script on Server to print your reports and email them. You won't be able to as that step is not server compatible. When you are in the Script Workspace the third icon from the right at the top allows you to see all the steps either in your currently selected script or in the list of all scripts which are compatible under the option you selected. Here is a screen shot of that.

          Screen Shot 2015-08-14 at 4.58.20 AM.png

          So if you need to print and send pdfs at this time you'll have employ some other method or use a robot machine for that.


          As for transferring your global memory variables. Think of the script that runs on server just as another user that has logged into the server, except that the other user in this case is really just a clone of you. So if you need to have anything transfer over to the script running on server you'll have pass that over in your script parameters. At Beezwax we have been using for a long time a reliable method of passing script parameters based on a set of custom functions that were designed by Six Fried Rice many years back with some slight modifications to them.


          To learn more about PSoS ( Perform Script on Server ) I wrote 2 blog posts when it first came out that are worth checking out.


          100x Faster – Flight Testing FileMaker 13 Perform Script on Server – Part I

          What Are Your Imports Waiting For? FileMaker 13 Perform Script on Server – Part II


          As far as printing goes there is something that we have used in the past but don't have all the details about it but you can look it up and read about it at wkhtmltopdf. Basically taking HTML formatted data and generating a PDF.




          Best - Vince

          • 2. Re: Server Side Scripting
            Markus Schneider

            thanks for bringing this back to attention! Is there no way to have 'pinned' postings/threads here?

            • 3. Re: Server Side Scripting

              I am not sure about that.

              • 4. Re: Server Side Scripting

                As previously noted by Vince, you can't create PDFs on the server.  But you can create it in FMP and store it in a container field and PSoS and export it on the server to the Temporary folder and attach it to an email sent by the server.  That would solve your problem. 

                • 5. Re: Server Side Scripting



                  Isn't the export field contents step not server compatible.


                  I think to accomplish this one would have to employ the technique discussed in this blog post.




                  Or am I missing something.



                  • 6. Re: Server Side Scripting



                    Thank you for the reply,


                    I have made a table with generic field names and a few for each type of file (ie number, text, date, etc). This while on the client version I create the pdf and store it on the server via a share network file path. (works fine) I then take all the variables I need and pass to the server and create new (and only) record in the temp table. Now once on the server I go find the first and only record of this temp table and pick them back up on the server. (works fine)


                    Now I am able to send the email using the passed variables however, I am not getting the attachment the attachment to the email.


                    So on the client side I create the pdf. with




                    On the server side "Send Email" script step I use




                    and for that matter I even tried to directly link to the file to test but still fail to attach it to the email.


                    Where have I gone astray? It would seem to be a slam dunk directly naming the file but I still miss something.


                    Thanks again



                    • 7. Re: Server Side Scripting

                      Hey Jason,


                      What you need to remember is that server side scripts can also access data from 2 places.


                      The Temporary Directory ( a temporary directory is created every time a script is run )

                      The Documents Directory


                      So I would recommend you look at this blog post...




                      To understand how you could host a database where your externally stored containers would live in the Documents directory. That way when you attach the path its a path that your FileMaker script can have access to.



                      • 8. Re: Server Side Scripting



                        Well thank you for the article very helpful, I have been about to send the pdf to the documents directory and pick it up as the attachment on the email.


                        I thought I saw a Greg do an export field contents to automatically delete the file from the directory.  Do you know the details?


                        Again thank you



                        • 9. Re: Server Side Scripting

                          Nope I do not know the details. Look forward to listening to Greg's talk when it is available.

                          • 10. Re: Server Side Scripting

                            Well, you can't directly export field contents for a container field, but you can via Base64 conversion and exporting the field as a text field and importing it and decoding it.  Here is a quick example of doing that.  


                            Set Variable [ $SP ; Value: Get ( ScriptParameter ) ]


                            If [ $SP = "Server" ]

                              Go to Layout [ “Test” (Test) ]

                              Enter Find Mode []

                              Set Field [ Test::Record ; 1 ]

                              Perform Find []

                              Set Variable [ $PDFBase64 ; Value: Base64Encode ( Test::Container ) ]

                              Set Field [ Test::Field ; $PDFBase64 ]

                              Set Variable [ $Path ; Value: Get ( DocumentsPath ) & "file.txt" ]

                              Export Records [ No dialog ; “$Path” ; Macintosh ]

                              New Record/Request

                              Import Records [ No dialog ; “$Path” ; Add; Mac Roman ]

                              Set Variable [ $Container ; Value: Base64Decode ( Test::Field ; "statement.pdf" ) ]

                              Set Field [ Test::Container ; $Container ]

                              Exit Script [ Result: Get ( LastError ) ]

                            End If


                            Perform Script on Server [ Wait for completion ; “Test” ; Parameter: "Server" ]

                            Show Custom Dialog [ Get ( ScriptResult ) ]

                            • 11. Re: Server Side Scripting

                              Deleting a file is as simple as exporting a file from a layout that has a zero count found set.

                              • 12. Re: Server Side Scripting

                                Once I have the file stored in the documents file of the server is it possible to pick it back up on the server side with a $variable in the server side script? (for attaching to the email)


                                It will pick up the file if I have it hard coded as the attachment name.


                                $variable does not seem to work for the file name



                                • 13. Re: Server Side Scripting

                                  FMS can only touch files that are in the FMS documents folder.  So if the file is not there it won't work...

                                  • 14. Re: Server Side Scripting

                                    This is the path I have pointed it to which I thought was the server documents folder. This is the script I am created to support this email.


                                    Have I used the variable incorrectly?





                                    1 2 Previous Next