Skip to main content

Autocomplete suggestions

Assist-text fields use Studio scripts to provide suggestions while allowing free-text input.

Configure a suggestion script​

  1. Create a Studio server script. Paste the example into its TypeScript entry file, then compile, save, and publish
  2. Open Work > Forms, select the form, then open Field Design and create or edit an Assist Text field
  3. Set Suggestion Source to Studio Script, select the script and entry file, and save
  4. Open the form create or edit page to test suggestions

Readonly tables, details, and filter conditions do not execute suggestion scripts.

Script function​

Use built-in types without imports. The optional second parameter is context: StudioScriptContext. Use field.autocompleteSuggestions for binding-aware compilation.

// Purpose: Test dynamic suggestions for assist-text fields.
// Constraints: Return text only; no business data access or mutations.
export default async function main(
payload: AutocompleteSuggestionsPayload,
): Promise<AutocompleteSuggestionsResult> {
const candidates = [
'Product Manager',
'Project Manager',
'Frontend Engineer',
'Backend Engineer',
'Test Engineer',
'Sales Manager',
];
const query = payload.input.query.trim().toLowerCase();
if (!query) return { suggestions: [] };
return {
suggestions: candidates.filter((text) =>
text.toLowerCase().includes(query),
),
};
}

Input Payload​

PropertyTypeMeaning
schema'soln.runtime-context/v1'Runtime context version
source.type'autocomplete_suggestions'Suggestion source
source.scope'main' | 'child'Main or child field
source.fieldApiNamestringCurrent field API name
formRuntimeFormRef | nullSource form
draft?.dataRecord<string, unknown>Current parent draft values
child?.row?.dataRecord<string, unknown>Current child-row values
selection.childRowsRuntimeChildRow[]Available child rows
input.querystringQuery text; only requested after non-empty input
runtime.localestringRuntime locale
runtime.timezonestringRuntime timezone

Read fields by API name, such as payload.draft?.data.department. This event does not preload persisted records; record is null.

Response​

type AutocompleteSuggestionsResult = {
suggestions: string[];
};

Each text is both displayed and inserted. No label, value, or effects properties are needed.

  • Return { suggestions: [] } for no matches
  • Surrounding whitespace, empty texts, non-strings, and duplicates are removed. Order is preserved
  • The runtime accepts at most 100 valid texts per execution
  • Object options [{ label, value }] are not accepted
  • Queries use a 250ms debounce. Scripts filter using input.query; the frontend also applies case-insensitive substring matching
  • Execution failures leave suggestions empty without preventing free-text input

Test steps​

  1. Focus an empty field: no suggestions appear until text is entered
  2. Enter “Engineer” to see three matches, or “Manager” to see three matches
  3. Select “Product Manager” to insert that exact text
  4. Enter “Designer”: no suggestions appear, but the text can still be saved

Download the Chinese test script