• Please enter your DISQUS subdomain in order to use the 'Disqus Comments (for Joomla)' plugin. If you don't have a DISQUS account, register for one here

Core FileMaker Blog

Keep up to date with CoreSolutions

Different Approach to Handle PDF Printing via WebDirect

[Updated March 22, 2016]

After working on a solution that eventually became FileMaker WebDirect-ified, it became quite evident that we needed to find a way to do reporting from web-based clients. As most of you are probably already aware, the very useful “Save as PDF” script step that FileMaker Pro provides is not available to clients accessing your system via Web Direct. There are a number of solutions to this problem already, but I had problems getting some of them to work, and others didn’t quite fit the bill.

As a result of this dilemma, I decided to roll on my own - I ended up creating a module that is relatively easy to implement, flexible, and even allows you to reuse your existing reporting scripts should you find yourself in a situation similar to mine.

What This Module Is

This module is essentially a framework for telling a FileMaker Web Direct session to hand off a script to a FileMaker Robot machine. You might be wondering what I mean by a FileMaker Robot machine… Good question! When I refer to a FileMaker Robot machine, I’m essentially talking about an installation of FileMaker Pro that sits idly by with no users working on it. When a FileMaker Robot machine is configured properly with this module, it will essentially just wait for a FileMaker Web Direct user to ask it to run a script for them. This is particularly handy in cases where FileMaker Pro is capable of doing things that FileMaker Web Direct is unable to.

How to Install this Module

  1. Copy tables
  2. Copy custom functions
  3. Clean up the layouts that are automatically created (delete everything but the "Container" field, make the layout blend in with your system, and make that container field take up the majority of the screen)
  4. Copy the main script folder (Perform Script On Robot) from sample solution into yours
  5. Create a new account in your system to be used by the robot. The default account name is "Robot", though this can be changed in the config file
  6. Modify the "PSOR Config" script (Optional)
  7. Attach the "PSOR On Record Load - Look For New Jobs" script as an On Record Load script trigger on the "PSOR_ActiveJobs" layout
  8. Attach the "PSOR On First Window Open" and "PSOR On Last Window Close" as script triggers on the file
  9. Login to the system with your “Robot” account from FileMaker Pro on the robot machine

Once installed, the solution can be very simple to implement. To understand how to implement it, you should keep in mind that the goal of this module was twofold; to be able to create PDF’s seemingly from WebDirect and to be able to reuse the same scripts that create those PDF’s from FileMaker Pro clients. After all, who likes rewriting code to do the same thing multiple times?

Keeping that in mind, with just a couple of simple additions, every one of your scripts that generates a PDF file can probably be modified so that it can be run from your Robot machine as well.

  1. Each one of those scripts will need a section at the top that determines if the script should continue running, or be handed off to the robot to continue (see sample file for details on this) #IF THIS IS BEING RUN FROM WEB-DIRECT, HAVE THE ROBOT MACHINE RUN THIS SCRIPT INSTEAD IF [ $$IAMWEBDIRECT ] PERFORM SCRIPT [ “PSOR - ASK ROBOT TO RUN THIS” ;           PARAMETER: INFOFORROBOT__CF ( )GO           //& NAMEVALUEPAIR_BROWSE__CF ( _NAME ; _VALUE )           //& NAMEVALUEPAIR_FIND__CF ( _NAME ; _VALUE ) ] END IF #ROBOT MACHINE RUNS EVERYTHING UNDER THIS LINE, AND SHOULD EXIT WITH THE PATH TO THE PDF THAT WAS CREATED
  2. Each one of those scripts should create a PDF (or some kind of file), and exit the script with a result representing the path to that newly created file

If everything went smoothly, then anytime you try to run one of your newly modified scripts from WebDirect, the handoff should take place, and the user will be left on a screen that displays the PDF.

If you're interested in the actual solution, you can download it here.

And if you enjoy our FileMaker Blogs, be sure to subscribe to our Core FileMaker Newsletter!

Have any questions or comments about this solution? Have anything you would like to add or change? Feel free to let us know in our comments section below.

And as always, thanks for reading!

Matt Leering

Leave a comment


  • Joshua Brock
    Joshua Brock 15 June 2017 Report

    Matthew - Thanks for this! Just came across this limitation on FM14 and WebDirect. Just started researching the 'robot' option. However as I understand it, rather than it being a specific machine being the 'robot'....can the 'robot' be an account located on the FM server? I ask as we're having DataTrium host the solution for this and I wouldn't have a separate machine being logged into the database.

    Thanks! Joshua

    Comment Link

  • Todd Dixon
    Todd Dixon 18 January 2017 Report

    Looked forward to getting this to work but I too got no resultant PDF. I also noticed those 'missing' Perform Script entries. Looking forward to seeing a revamped version (assuming that this is what is causing the issue.)

    Comment Link

  • Matthew Leering
    Matthew Leering 19 December 2016 Report

    Hi Chris; Thanks for the feedback. I re-downloaded a copy of this solution, and found what you were talking about. I found two spots with 'Perform Script' without a script specified, and I have a sneaking suspicion that I know what they were originally. Often times in my solutions, I have a script that accepts a boolean parameter, and will disable or enable the use of script triggers based on that parameter's value. This COULD be what's causing your issue, but it's tough to say without further information. I will try to update this solution shortly. Thanks for pointing this out.

    Comment Link

  • Chris
    Chris 08 December 2016 Report

    Tried to implement, but not getting a PDF to generate. In the solution file I downloaded, I noticed in script PSOR - Process Current Job, line 20 is Perform script . Is this the problem? If so, what script should be running here?

    Comment Link

  • Matt Leering
    Matt Leering 03 November 2016 Report

    Hey Rudi!
    Glad it's working out well for you.

    Unfortunately, script variables ($) have a scope that's limited to the script that created them;
    Global variables ($$) are limited to the file that they were created in;
    And global fields are limited to the session that they were created in.

    My recommended solution is to take advantage of some of the optional parameters that can be passed to my 'PSOR - Ask Robot To Run This' script. It's not really well documented, but you'll notice in my 'Sample Report Script' that I have a couple of commented out function calls in the script parameter:

    //& NameValuePair_Browse__cf ( _fieldName ; _value )
    //& NameValuePair_Find__cf ( _fieldName ; _value )

    Both commented out lines of code here are referencing custom functions which I have created.
    They both take 2 parameters:
    _fieldName => a fully qualified fieldname (I recommend using GetFieldName())
    _value => the value that is to be set into specified field

    Each of these custom functions can be called an arbitrary number of times (simply by concatenation ... as they don't return anything). When the robot machine receives them, they get handled differently based on whether the browse mode ones were used and/or the find mode ones were used.

    The find mode ones will be used by the robot in find mode -- so that you can try to recreate the same found set for instance,
    and the browse mode ones usually get used for setting some fields in browse mode (ie a global field).

    What I might recommend, is that you use a browse mode one to set a global field equal to the account name of the person running the script from web direct, and then you in turn set that value into the account name field of your choice within your own script.

    I know this is pretty wordy, but I hope this makes sense.

    Best Regards;

    Comment Link

  • Dewayne
    Dewayne 13 October 2016 Report

    Not getting this to work when integrating it into my solution. Does not create the PDF. Any suggestions.

    Comment Link

  • Aleksandar
    Aleksandar 05 February 2016 Report

    LIFESAVER! Works perfectly! GREAT JOB

    Comment Link