- Documentation
- Workflows
- Workflow Nodes
- Document workflow nodes
Document workflow nodes
Start a workflow when a file is added to, replaced in or deleted from a folder, and read a document's text and file in a workflow.
Documents provide four workflow nodes:
| Node | Type | Use it when |
|---|---|---|
| File Added | Trigger | A workflow should start when a new file lands in a folder. |
| File Replaced | Trigger | A workflow should start when a file in a folder gets a new version. |
| File Deleted | Trigger | A workflow should clean up after a file is deleted from a folder. |
| Get Document | Action | A step needs a document's details, its text or its file (for example to read it with AI Extract). |
Each trigger does one job. To react to both new and replaced files, add both File Added and File Replaced to the same workflow: they give the same fields, so the steps after them work for either.
The three file triggers
Pick the folder the trigger watches. The picker lists the folders you can view. A trigger watches exactly that folder: a file in one of its subfolders does not start it.
Open the workflow editor
Open the workflow that should react to the folder.Choose the trigger
Select the trigger slot, choose Documents, then select File Added, File Replaced or File Deleted.
Pick the folder
Choose the folder to watch. Publishing needs you to be able to view it.
Publish the workflow
New changes in the folder start runs once the workflow is published.
When they start
- File Added starts once the new file's text has been read.
- File Replaced starts once the new version's text has been read. Replace file and Restore on an older version both count as a replacement.
- File Deleted starts once the file is gone. Deleting a folder starts one run for each file directly in the watched folder.
Renaming a file, moving it to another folder or editing its description starts nothing. A file moved into the watched folder does not count as added.
If a file's text could not be read (for example a PDF locked with a password), File Added and File Replaced still start, with textStatus set to failed and the reason in failureReason, so the workflow can tell someone.
What $trigger holds
File Added and File Replaced give:
| Field | Value |
|---|---|
documentId | The document's id. Store it to find this file's rows later. |
name | The file's name, for example week-44.png. |
type | The file type: pdf, docx, xlsx, png, jpeg, txt or csv. |
folderId | The folder the file is in. |
folderName | The folder's own name. |
versionNumber | 1 for a new file, higher after a replacement. |
uploadedBy | Who uploaded this version (name, userId), or null if they no longer exist. |
link | The document's page in the app. |
text | The full text that was read, or null when it could not be read. |
textStatus | ready or failed. |
failureReason | Why the text could not be read, when textStatus is failed; otherwise null. |
truncated | true when the text was cut at the size limit. |
File Deleted gives documentId, name, folderId and folderName.
The text is passed whole. A very long document can be more than an AI step accepts; that step then fails with its usual error, which an error route can handle.
Get Document
Get Document reads one document of the workspace: the same fields as the triggers, plus file, a copy of the document's file that a later step can read. Set Document to {{ $trigger.documentId }}, or paste the id from the document page's address.
To read a scan or a photo, set AI Extract's File to extract from to the Get Document step's file, for example {{ $steps.get_document.data.file }}; AI Extract reads it by vision.
Get Document reads only documents in folders the person who published the workflow can view. When you test the step, it reads only documents in folders you can view.
Testing Get Document on its own gives every field except file, which is null: files are not available when you test a step on its own. Run the workflow to get the file.
Find a file's rows with source_document
To keep rows that came from a file in step with that file, give the table a text column named source_document with Searchable turned on. In Create Row, set it to {{ $trigger.documentId }}. Find Rows by that column then returns exactly the rows one file produced.
Two ready-made patterns
Extract to table (one workflow with File Added and File Replaced on the same folder):
- Find Rows where
source_documentis{{ $trigger.documentId }}. - Loop over the rows and Delete Row each one. A new file has none.
- Get Document with
{{ $trigger.documentId }}. - AI Extract with the document's
file. - Check the extracted values.
- Create Row for each one, with
source_documentset to{{ $trigger.documentId }}.
A replaced file's old rows are removed and rows from the new version take their place.
Cleanup on delete (on File Deleted):
- Find Rows where
source_documentis{{ $trigger.documentId }}. - Loop over the rows and Delete Row each one.