Skip to main content

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:

NodeTypeUse it when
File AddedTriggerA workflow should start when a new file lands in a folder.
File ReplacedTriggerA workflow should start when a file in a folder gets a new version.
File DeletedTriggerA workflow should clean up after a file is deleted from a folder.
Get DocumentActionA 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.

  1. Open the workflow editor

    Open the workflow that should react to the folder.
  2. Choose the trigger

    Select the trigger slot, choose Documents, then select File Added, File Replaced or File Deleted.

  3. Pick the folder

    Choose the folder to watch. Publishing needs you to be able to view it.

  4. 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:

FieldValue
documentIdThe document's id. Store it to find this file's rows later.
nameThe file's name, for example week-44.png.
typeThe file type: pdf, docx, xlsx, png, jpeg, txt or csv.
folderIdThe folder the file is in.
folderNameThe folder's own name.
versionNumber1 for a new file, higher after a replacement.
uploadedByWho uploaded this version (name, userId), or null if they no longer exist.
linkThe document's page in the app.
textThe full text that was read, or null when it could not be read.
textStatusready or failed.
failureReasonWhy the text could not be read, when textStatus is failed; otherwise null.
truncatedtrue 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):

  1. Find Rows where source_document is {{ $trigger.documentId }}.
  2. Loop over the rows and Delete Row each one. A new file has none.
  3. Get Document with {{ $trigger.documentId }}.
  4. AI Extract with the document's file.
  5. Check the extracted values.
  6. Create Row for each one, with source_document set 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):

  1. Find Rows where source_document is {{ $trigger.documentId }}.
  2. Loop over the rows and Delete Row each one.
Was this helpful?