Automating tasks with scripts > Creating and editing scripts > About running scripts on FileMaker Server
 
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:
a Perform Script On Server script step in a script running on a client
a FileMaker Server schedule (see FileMaker Server Help)
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 Compatibility button, 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.
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 and are already opened by the client.
Scripts run by Perform Script On Server use the same account as the client. Scripts run by a FileMaker Server schedule use the account specified in the schedule (see FileMaker Server Help). The account’s privilege set must have the fmapp extended privilege enabled. See Editing extended privileges for a privilege set.
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
the script encounters an unknown script step (see Allow User Abort script step)
See FileMaker Server Help.
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.