Hi, this is David from AppWorks, and I’m going to do another Cool Trick video today. We’re going to go over how to have a script in FileMaker perform itself on server. So it’s going to recursively call itself, and run on server, instead of running on the local machine. This can speed up operations a lot when you’re running PSOS, is what we call perform script on server. I did write up a blog article on this in 2015 when this feature came out on version 13 of FileMaker, so if you want to go to our website,, and do a search in the search bar on our blog for perform script on server, or automatically perform script on server, we’ve got a nice description of it and some sample code that you can see. I’m going to show you this because I consider this to be a cool trick.

So basically we’ve got a database, this is hosted on one of our dev servers, and I basically wrote a demo script that grabs a state name, grabs these company records, takes that state and updates a date field. It takes a while locally, so in this old demo that I built, basically you take one script, you say what state would you like to update, put that in a variable, and then you send that variable to another script, which is perform on server. So you use the PSOS script step, send the state name, then you get the result of the script and it says success or failure. The subscript that you would fire off takes the script parameter, does the stuff, goes to a layout, enters find mode, does these things, replaces fields,  and then exits. So not a big deal, but it is two scripts to maintain, so I find it to be a little more elegant to just have one script that calls itself, and the cool trick about this is that it’ll actually call itself on server if a server exists, but if this is a local copy, running locally, it’ll still work locally. 

You do have to make a few little adjustments, but this is a script that calls itself. So basically, I’ve combined these two scripts into one. So we say show custom dialog, grab the state name, and then we say we have an if statement. This section here actually is the only part that runs locally on the local machine, unless you are not hosted on server. That’s not what we’re talking about here. So the rest of this is the only part that’s performed on server, including this first script step.

So what we do is say if the pattern count of the application version we’re currently running does not have the word server in it, so you can look for the word server in the application version, right now we’re just running FileMaker Pro Advanced. So it does not have the word server in it. So there’s fewer than one time in the pattern count. So that’s true, and the integer, get number, get host application version, and this checks to see if there’s a hosted version of FileMaker, meaning a server version. If there’s not, it won’t have a number and this will fail, and the script will just skip down here and start running locally. If, however, we’re not running on server right now, and there is a server hosting this file that is greater than or equal to version 13, it should run successfully by PSOS. So, now we can perform this script, which is the script that we’re currently running, so it’s calling itself on server and sending the state parameter. Then we wait for completion, and we get the result, and then we show the result and now we exit the script. You have to exit the script right here, otherwise it’ll run it again locally. So now what happens is when it gets on the server, it ignores this because it can’t show a custom dialog on server. The server then goes straight to here, grabs the state, runs this part on the server, exits, and then comes down to here, and that’s basically the whole technique. 

So when we run this, you’ll see the script debugger show custom dialog. I’d like to update the state of Texas, now if PatternCount and Get ( ApplicationVersion ) ; “Server” is fewer than 1 and the server version is greater than or equal to 13 is true, now we’re going to perform myself on server, and you can see it just updated some records here. We get a script result, and we had success, and then we’re done. So that’s the cool trick, hope you enjoyed it, and make some comments if you have any questions, and visit our website if you want to check out the blog article. Thanks.