Find the PSOS Demo file here


Hi, this is David at AppWorks and today I’m going to talk to you about performing scripts on the server. It’s a feature in FileMaker that can save you tons of time performance-wise, when you’re doing operations that require you to manipulate a lot of records or do something that’s going to be complicated, and actually takes quite a long time. If you can completely encapsulate the operations in a single script that can run without any user input, then you can probably offload it to the server. I’m going to show you what the real benefit of running things on the server is. Here I’ve got a basic script. It’s called find and update. It asks the user to input a state, goes into find mode, enters the state and a company table, performs a find for all the records with that state, then replaces field contents in a different field.

This is a table, just companies and address data. If I run this script locally, which means I’m just going to run this operation right here from my client, but it’s operating on data from the cloud on a hosted server and I choose, say, Delaware. I’m going to replace with calculated result, hit replace. Takes a second and it’s done. That was only 132 records. If I run this again with a state like Texas, there are 1100 records, well let’s see what that does. As you can see, this is going to take a while. So, what’s happening here is that this script has to actually pull 1100 records down from the hosted database to my local machine, cash them, manipulate them, and send the data back up to the hosted machine. Takes a long time when you’ve got a lot of records. That was a good 8-10 seconds. Here’s the difference – if I run the same operation and split the essential script into two scripts, one that just sends the information up to the server, and one that runs on the server, with PSOS, it’s going to be much baster. So if we run this and we say California, which actually even has more records, and it’s done! That’s how quickly it worked.

If you want to see just how much faster that was, California actually has 2400 records, about twice as many as Texas, and yet it was a split second and done. So, this is the real benefit of PSOS. The way you do this is you take these operations that you can do on server all by themselves, split them out in a second script, so you can see here, we’ve got entering find mode, setting the field, performing the find, there’s some error checking here, we’re actually replacing field contents here. This is all the same stuff that happened in this script only what we’ve done is split it onto the server, so the stuff that takes a long time, we’ve put onto the server. We’re going to show custom dialog, I’ll run through it quickly. We’re going to ask for CA again, hit OK, and now, at this point, this $state variable gets sent as a parameter to the PSOS subscript. When the PSOS subscript is done, we wait for completion. You can see here it says wait for completion: On, and then we set a variable after its completed to the result, and we get the script result. Now I’ve set up the script so that it actually sends a result when it’s done, and then it displays a custom dialog with the result. So we hit PSOS, now we set the variable result, and we show the result. Success. Now we’re done.

You’ll see in this PSOS subscript what we do here. First, we set a variable to the state. We get the script parameter that we sent in, and this is all happening on the server. We go to a layout Company, you need to do this because your startup script may take you to a different layout like the splash screen, which is the wrong context. You’re not going to find company records on this screen, so your script will fail if you don’t go to the right place. You can’t control this, you can’t have a user setting it to the correct layout, so you need to do everything that a user would need to do on this script. Sp now we enter find mode on the server, we set the field of state, which we got from the parameter, we perform the find, this is all happening on the server. If the find doesn’t work for some reason, say we do a search for California, it won’t find any records that have California in the state. It’ll throw an error and now if you see an error, meaning if there’s an error that’s’ more than zero, then you’re going to exit the script, and you send the results of the dollar error.

Otherwise, we’re going to do our operations, so if there was no error finding this, we exit the script again. This time we send a text result of success. Exit script with a text result means that when this script gets the script result, that’s what we see. So if you have an error, for example if we run this and we say California, and 401. There was an error, error 401. Error 401 means records not found. So, that’s basically it. You need to be able to send parameters in, you need to make sure that you’re in your correct context, so go to a layout, and then you can do your operations on the server and you also want to then trap for some errors and send errors back out or send some sort of success or result back out. This script will pick it up, send it back to the user, and now you’ve saved yourself tons of time. That’s basically how PSOS works. This file will be downloadable from our website, so check it out, and see how it works for yourself. Thanks for watching, bye.