Scripting
Write JavaScript transform scripts to batch-modify documents with preview and diff.
Overview
The Scripting feature lets you write JavaScript transform functions that run against records in a collection or table. Scripts execute in a sandboxed environment with a preview step that shows exactly what changes will be made before you apply them.
Opening the Script Editor
Open the Script Editor from the toolbar. The editor panel appears with a code editor, template selector, and action buttons.
Writing a Script
Your script receives a doc object representing each document and returns the modified document. The transform function runs once per document.
// Rename a field
function transform(doc) {
doc.displayName = doc.userName;
delete doc.userName;
return doc;
}
// Add a computed field
function transform(doc) {
doc.fullName = `${doc.firstName} ${doc.lastName}`;
return doc;
}
// Normalize a field value
function transform(doc) {
if (doc.email) {
doc.email = doc.email.toLowerCase().trim();
}
return doc;
}
Built-in Templates
Stackpane includes several common templates to get started quickly:
- Rename Field — rename a field across all documents
- Delete Field — remove a field from all documents
- Add Default Value — add a field with a default value where it does not exist
- Type Conversion — convert a field from one type to another (e.g., string to number)
- Timestamp Migration — convert date strings to Firestore timestamps
Select a template from the dropdown to load it into the editor, then customize it for your use case.
Preview and Diff
Before applying changes, preview them:
- Click Preview to run the script against loaded documents.
- A diff table shows each document with its before and after state.
- Added fields are highlighted in green, removed fields in red, and changed values in yellow.
- Review the changes carefully.
The preview runs entirely in memory without making any API calls or modifying your data.
Applying Changes
Once you have reviewed the preview:
- Click Apply Changes to execute the script against the collection.
- Stackpane processes documents in batches and shows a progress indicator.
- Each document is updated with the transformed values.
- A summary shows the number of documents modified, skipped, and any errors.
Saving Scripts
Save scripts for reuse:
- Write or modify a script in the editor.
- Click Save and enter a descriptive name.
- Access saved scripts from the Saved Scripts menu.
- Load a saved script to use it again or modify it.
Saved scripts persist across sessions and are available for any collection.
Safety
Scripts run in a sandboxed environment and cannot access the network, filesystem, or other system resources. The preview step ensures you can verify changes before they touch your data.