ProofKit

Usage Examples

Prerequisites

Before you can use any of these methods, you need to set up a FileMaker Data API client. If you haven't done this yet, check out our Quick Start Guide to create your client in a separate file.

For these examples, we'll assume you've already setup a client in another file and are importing it for use.

// This is just an example - follow the Quick Start guide for your actual setup
import { CustomersLayout } from "./schema/client";

Retrieving Data from FileMaker

Finding Records

You can use the find method to perform FileMaker-style find requests on a layout. This method is limited to 100 records by default, but you can use the findAll helper method to automatically paginate the results and return all records that match the query.

searchCustomers.ts
// Simple search - find customers in a specific city (max 100 records)
export async function (: string) {
  const  = await .({
    : { :  }
  });
  
  .(`Found ${..} customers in ${}`);
  return .;
}

// Get ALL matching records at once (handles pagination automatically)
export async function () {
  const  = await .({
    : { : "==Active" } // all standard FileMaker operators are supported
  });
  
  return ;  // All active customers, no pagination needed
}

Use an array of find requests to get the OR behavior, equivalent to having multiple find requests in FileMaker.

multipleFindRequests.ts
export async function (: string, : string) {
  const  = await .({
    : [{  }, {  }]
  });
  
  return ;
}

There are also helper methods for common find scenarios. Any of these methods will return just a single record instead of an array.

  • findOne will throw an error unless there is exactly one record found
  • findFirst will return the first record found, but still throw if no records are found
  • maybeFindFirst will return the first record found or null

Getting All Records

If you don't need to specify any find requests, you can use the list or listAll methods. list will limit to 100 records per request by default, while listAll will automatically handle pagination via the API and return all records for the entire table. Use with caution if the table is large!

getAllCustomers.ts
// Get a page of customers (recommended for large datasets)
export async function () {
  const  = await .({
    : [{ : "firstName", : "ascend" }]
  });
  
  return {
    : .,
    : ..,
    : .. === 100 // Default page size
  };
}

// Get ALL customers at once (use with caution on large datasets)
export async function () {
  const  = await .();
  
  .(`Retrieved all ${.} customers`);
  
  return .( => ({
    : .,
    : ..,
    : ..,
    : ..,
    : ..
  }));
}

Creating Records

Use create to add new records to your FileMaker database.

createCustomer.ts
export async function (: {
  : string;
  : string;
  : string;
  ?: string;
  ?: string;
}) {
  const  = await .({
    : {
      : .,
      : .,
      : .,
      : . || "",
      : . || "",
      : "Active",
      : new ().()
    }
  });
  
  .(`Created customer with ID: ${.}`);
  return .;
}

Update / Delete Records

Updating or deleting records requires the internal record id from FileMaker, not the primary key for your table. This value is returned in the recordId field of any create, list, or find response.

This record id can change during imports or data migrations, so you should never store it, but instead alwyas look it up via a find request when it's needed.

updateCustomer.ts
export async function (: string, : {
  ?: string;
  ?: string;
  ?: string;
  ?: string;
}) {
  const { : {  } } = await .({ : { :  } });

  // Only update fields that were provided
  const : any = {};
  if (.) .firstName = .;
  if (.) .lastName = .;
  if (.) .phone = .;
  if (.) .city = .;
  
  const  = await .({ ,  });
  return .;
}
deleteCustomer.ts
export async function (: string) {
  // Optional: Get customer info first for logging
  const { : {  } } = await .({ : { :  } });

  await .({});
}

Working with Scripts

FileMaker scripts can be executed during any other method or run directly.

Running Scripts Directly

Use executeScript to run a script directly.

executeScripts.ts
export async function () {
  const  = await .({
    : "Send Email",
    : .({
      : "customer@example.com",
      : "Welcome to our service",
      : "Thank you for signing up!"
    })
  });
  .("Script result:", .);
  return .;
}

Run a script with another method

You can run scripts before or after any data operation. The script will be run in the context of the layout specified in your client and will be on the record or found set as the operation. This is especially useful when creating records, as you can run a script after the record is created, knowing the script will be focused on this newly created record; thus giving you access to the calculated values such as a UUID primary key defined in your field definitions.

scriptsWithOperations.ts
// Run a script after creating a record
export async function (: any) {
  const  = await .({
    : ,
    : "Send Welcome Email", // script name

    // script param must always be a string
    "script.param": .({
      : .email,
      : `${.firstName} ${.lastName}`
    })
  });
  
  return {
    : .,
    : .
  };
}

For more details about the script execution order, see this page of the FileMaker Data API guide.


See also