About running scripts on FileMaker Server
Scripts in files hosted by FileMaker Server normally run on the
client. However, you can run a script on the server (a server-side script) by using:
How scripts run differently on FileMaker Server
A script started by either above method is run by the FileMaker Script Engine (FMSE), a component of FileMaker Server. The FMSE is a client that runs each script in a separate session on the server. As a result, server-side scripts:
•don’t have the client’s context (current layout, found set, sort order, record, global field values, and local or global variable values)
You can pass information about the client’s context to a server-side script by using the script parameter in the Perform Script On Server script step. The server-side script can use that information in script steps like the
Go to Layout script step and
Perform Find script step to specify which layout and found set to act on.
•support script parameters and script results up to 1 million characters
•can access other FileMaker Pro files only when both of the following are true:
•the files are on the same host
•the files were already opened by the client that started the server-side script, or set up with an account name and password specified in the file’s File Options dialog box
Server-side scripts run the same way regardless of how they’re started, except for the following:
•A client using the Perform Script On Server script step has the option to wait for the script to complete on the server and use the
Get(ScriptResult) function to capture the result.
•A FileMaker Server schedule can be set to abort if the running script exceeds the specified time limit.
Handling unsupported script steps
Many script steps are supported by the FMSE. However, attempting to perform an unsupported script step returns error 3 ("Command is unavailable"), skips the unsupported step, and continues to the next step. To handle unsupported steps, your script can use the If script step with:
•the
Get(LastError) function after a step in order to check whether that step is unsupported, then perform supported steps instead. For example, the Open File script step is unsupported by the FMSE, so the following script running on the server will skip that step and return "unsupported" in the result.
Open File [Open hidden: Off ; "Invoices Backup"]
If [ Get(LastError) = 3 ]
Exit Script [ Text Result: "unsupported" ]
End If
•the
Get(ApplicationVersion) function before other steps in order to check whether the script is running on FileMaker Server, then perform only supported steps. For example:
If [ PatternCount ( Get(ApplicationVersion) ; "Server" ) > 0 ]
# Continue with script steps supported by the FMSE
End If
To see which script steps are supported by the FMSE, in the Script Workspace in FileMaker Pro, open a script, click
, then select
Server. Script steps that aren’t supported appear in a different color. You can also refer to the Compatibility table for each script step in
Script steps reference.
Reasons to run a script on the server
•to improve performance by reducing the amount of network traffic between the client and server
•to offload long-running tasks from slower clients to a faster server
•to enable FileMaker Go clients to perform tasks that require
plug-ins, which are supported on FileMaker Server but not on FileMaker Go
•to use the Import Records or Execute SQL script steps with an
ODBC data source that uses the server’s
DSN Notes
•If records are locked by a client, server-side scripts cannot access uncommitted data or change the contents of those records.
•Server-side scripts can use the
Perform Script script step to perform
sub-scripts, which also run on the server, only if those sub-scripts are in files on the same server and are already opened by the client.
•Server-side scripts can’t cause a client to display FileMaker alert messages as when scripts are run on clients, so server-side scripts always perform as if the
Set Error Capture script step were set to On. Use the
Get(LastError) function in server-side scripts to handle error conditions. To help you troubleshoot problems, errors are also written to the event log on FileMaker Server.
•Clients can’t abort server-side scripts. However, a server-side script can be aborted if:
•a server administrator stops the script, which appears as a separate client that can be disconnected in FileMaker Server Admin Console
•the running script exceeds the time limit specified in the FileMaker Server schedule that started it
•In server-side scripts, functions related to hardware, such as Get(SystemIPAddress), return information from the database server component of FileMaker Server, not from the client.