Splitting app logic
In standard FileMaker layouts, interface behavior is defined through button actions, hide calculations, and script triggers. In a Web Viewer app, interface presentation and user interactions run client-side in JavaScript, while database interactions and backend transactions execute in FileMaker Pro.
Use the FileMaker Data API to read, write, and delete single records directly in JavaScript. For operations spanning multiple records or requiring transactional integrity, write a custom FileMaker script. See Call FileMaker scripts from an app for details on the fmFetch and callFMScript calling conventions.
Logic in JavaScript
Place user interface and client interaction logic directly in JavaScript:
-
Showing, hiding, and reordering interface elements.
-
Client-side routing between views. (Navigation can also be triggered from FileMaker scripts; see Navigate between FileMaker and an app.)
-
Capturing and handling user input events.
-
Managing form state, local validations, loading indicators, and error banners.
Logic in FileMaker scripts
Use FileMaker scripts whenever a data operation involves more than a single record update:
-
Transactions spanning multiple records that must commit or revert as a single unit.
-
Operations that trigger downstream workflows, such as updating related tables, sending email, or logging audit trails.
-
Business logic that must be enforced consistently across all client layouts and integrations.
-
Complex server-side data validations prior to creating or deleting records.
-
Workflows requiring secure API keys, local file system operations, printing, PDF export, or container file management.
Decision framework
When designing a data operation, determine whether secondary actions must occur alongside the record update:
-
Single-record CRUD: If the action is a simple record creation, read, update, or deletion with no side effects, call the Data API directly from JavaScript. You can also route through a script if preferred.
-
Multi-record or transactional: If the action modifies multiple records, enforces business rules, or requires transactional rollback, execute a FileMaker script.
Client-side Data API methods generated by Typegen do not support FileMaker transactions. If a workflow creates an invoice with line items, execute a single script rather than chained sequential create() calls:
await InvoiceLayout.create({ fieldData: invoice });
await LineItemLayout.create({ fieldData: lineItem });
import { fmFetch } from "@adk/fmdapi";
await fmFetch("Create Invoice With Line Items", {
invoice,
lineItems,
});
Scripts execute within the FileMaker security model. This allows the Web Viewer app to request privileged backend actions without exposing API secrets or proprietary business rules in client-side code.