About running scripts on FileMaker Server and FileMaker Cloud products
Scripts in files hosted by FileMaker Server and FileMaker Cloud products normally run on the client. However, you can run a script on the server (a server-side script) by using:
- the Perform Script On Server script step in a script running on a client
- a schedule (see FileMaker Server Help or FileMaker Admin API Guide)
How server-side scripts run differently
A script started by either above method is run by the FileMaker Script Engine (FMSE), a component of FileMaker Server and FileMaker Cloud products. 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 schedule can be set to end 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.Copy
Open File [Open hidden: Off ; "Invoices Backup"]
If [ Get(LastError) = 3 ]
Exit Script [ Text Result: "unsupported" ]
- the Get(ApplicationVersion) function before other steps in order to check whether the script is running on FileMaker Server or a FileMaker Cloud product, then perform only supported steps. For example:Copy
If [ PatternCount ( Get(ApplicationVersion) ; "Server" ) > 0 ]
# Continue with script steps supported by the FMSE
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 and FileMaker Cloud for AWS but not in FileMaker Go
- to use the Import Records or Execute SQL script steps with an ODBC data source that uses the server’s DSN
- If records are locked by a client, server-side scripts cannot access uncommitted data or change the contents of those records.
- Running server-side scripts opens and closes the files that contain the scripts. Therefore, the OnFirstWindowOpen script trigger is activated when the script starts and the OnLastWindowClose script trigger is activated when the script ends.
- 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. Additionally, when a client uses the Perform Script on Server script step to run a script that performs sub-scripts in another file, the file containing the sub-scripts must already be opened by the client.
- Scripts run by Perform Script On Server use the same account as the client. Scripts run by a schedule use the account specified in the schedule.
- Server-side scripts can’t cause a FileMaker client to display 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 and FileMaker Cloud products.
- Clients can’t stop server-side scripts. However, a server-side script can be stopped if:
- a server administrator stops the script, which appears as a separate client that can be disconnected in Admin Console for FileMaker Server or FileMaker Cloud products
- the running script exceeds the time limit specified in the schedule that started it
- the script encounters an unknown script step (see Allow User Abort script step)
See FileMaker Server Help or FileMaker Cloud product documentation.
- In server-side scripts, functions related to hardware, such as Get(SystemIPAddress), return information from the database server component of FileMaker Server and the FileMaker Cloud product, not from the client.
- For server-side scripts, file access is limited to the Documents folder and temporary folder. See Paths in server-side scripts.
- In server-side scripts, script steps with the With dialog option turned on can’t display dialog boxes and may return an error. To avoid this error, turn off With dialog in server-side scripts.