Reads each document you link, pulls out the details you asked for, and adds one Airtable record per document.

UsesAirtableOpenAI

Turn a pile of documents into an Airtable table

Give it a list of links to PDFs or images, say which details you want out of each one, and run it whenever you have a pile to file. Each document is read as written, the details you named are pulled out, and one record is added to your Airtable table per document.

Each record holds the link, a title, the document type, the details you asked for as one line each, and the date it was added. Before anything is written the link is looked up in the table, so a document already there is left exactly as it is and a re-run files only new links. Nothing is overwritten or deleted. A document that cannot be read is reported and skipped rather than stopping the run, each run takes a capped number of documents, and if nothing could be filed the run stops with a message.

Your table needs five columns before the first run: 'Document', 'Title', 'Document Type', 'Details' and 'Added'. Links have to serve the file itself rather than a preview page; uploaded files work too.

Set documentLinks to blank.Set documentLinks to blank.
Set detailsToPullOut to blank.Set detailsToPullOut to blank.
Set airtableBaseId to blank.Set airtableBaseId to blank.
Set airtableTableName to blank.Set airtableTableName to blank.
Set maxDocuments to 25.Set maxDocuments to 25.
Trim airtableBaseId and save it as baseId.Trim airtableBaseId and save it as baseId.
Trim airtableTableName and save it as tableName.Trim airtableTableName and save it as tableName.
Set detailFieldNames to an empty list.Set detailFieldNames to an empty list.
For each detailEntry in detailsToPullOut with "For each detailEntry in detailsToPullOut with “ ” replaced by “,” split by “,”:
Trim detailEntry and save it as detailName.Trim detailEntry and save it as detailName.
If detailName isn't emptyIf detailName isn't empty
Yes
Add detailName to the end of detailFieldNames and save it as detailFieldNames.Add detailName to the end of detailFieldNames and save it as detailFieldNames.
No
No steps
If detailFieldNames is emptyIf detailFieldNames is empty
Yes
Stop and report a problem: The 'detailsToPullOut' step has no field names in it. Write the details you want out of each document separated by commas - for example 'Supplier, Effective date, Contract value' - then run it again.Stop and report a problem: The 'detailsToPullOut' step has no field names in it. Write the details you want out of each document separated by commas - for example 'Supplier, Effective date, Contract value' - then run it again.
No
No steps
Combine [“Title”, “Document Type”] and detailFieldNames into one list and save it as fieldsToExtract.Combine [“Title”, “Document Type”] and detailFieldNames into one list and save it as fieldsToExtract.
Get today's date and save it as addedOn.Get today's date and save it as addedOn.
Set documentsRead to 0.Set documentsRead to 0.
Set filedCount to 0.Set filedCount to 0.
Set skippedCount to 0.Set skippedCount to 0.
Set failedCount to 0.Set failedCount to 0.
For each documentEntry in documentLinks with "For each documentEntry in documentLinks with “ ” replaced by “,” split by “,”:
If documentsRead is greater than or equal to maxDocumentsIf documentsRead is greater than or equal to maxDocuments
Yes
Show in the output: Stopped after documentsRead documents. Raise the 'maxDocuments' step to take more in one run.Show in the output: Stopped after documentsRead documents. Raise the 'maxDocuments' step to take more in one run.
Stop repeating.Stop repeating.
No
No steps
Trim documentEntry and save it as documentLink.Trim documentEntry and save it as documentLink.
If documentLink isn't emptyIf documentLink isn't empty
Yes
Add 1 to documentsRead.Add 1 to documentsRead.
If documentLink starts with “http” (ignoring case) or documentLink starts with…If documentLink starts with “http” (ignoring case) or documentLink starts with…
Yes
If a step below fails, save the error as documentErrorIf a step below fails, save the error as documentError
Try
AirtableAirtableList records in tableName. Save it as alreadyFiled.List records in tableName. Save it as alreadyFiled.
If alreadyFiled.records isn't emptyIf alreadyFiled.records isn't empty
Yes
Add 1 to skippedCount.Add 1 to skippedCount.
Show in the output: Already in the table, left alone: documentLink.Show in the output: Already in the table, left alone: documentLink.
No
Run an AI agent: Read the attached document and pull out each of these fields, in this order: - fieldsToE… and save it as extraction.Run an AI agent: Read the attached document and pull out each of these fields, in this order: - fieldsToE… and save it as extraction.
Set extractedFields to extraction.output.fields.Set extractedFields to extraction.output.fields.
Set documentTitle to blank.Set documentTitle to blank.
Set documentType to blank.Set documentType to blank.
Set detailLines to an empty list.Set detailLines to an empty list.
For each extractedField in extractedFields:For each extractedField in extractedFields:
Trim extractedField.name and save it as fieldName. Trim extractedField.name and save it as fieldName.
Set fieldValue to blank. Set fieldValue to blank.
If a step below fails, save the error as fieldIsAList If a step below fails, save the error as fieldIsAList
Try
Trim extractedField.value and save it as fieldValue.Trim extractedField.value and save it as fieldValue.
On error
Join extractedField.value with “, ” and save it as fieldValue.Join extractedField.value with “, ” and save it as fieldValue.
If fieldName is “Title” If fieldName is “Title”
Yes
Change documentTitle to fieldValue.Change documentTitle to fieldValue.
No
No steps
If fieldName is “Document Type” If fieldName is “Document Type”
Yes
Change documentType to fieldValue.Change documentType to fieldValue.
No
No steps
If [“Title”, “Document Type”] doesn't contain fieldName If [“Title”, “Document Type”] doesn't contain fieldName
Yes
Add fieldName: fieldValue to the end of detailLines and save it as detailLines.Add fieldName: fieldValue to the end of detailLines and save it as detailLines.
No
No steps
Set recordTitle to documentTitle.Set recordTitle to documentTitle.
If recordTitle is emptyIf recordTitle is empty
Yes
Change recordTitle to documentLink.Change recordTitle to documentLink.
No
No steps
AirtableAirtableAdd a record to tableName.Add a record to tableName.
Add 1 to filedCount.Add 1 to filedCount.
On error
Add 1 to failedCount.Add 1 to failedCount.
Show in the output: Could not file documentLink: documentError.message.Show in the output: Could not file documentLink: documentError.message.
No
Add 1 to failedCount.Add 1 to failedCount.
Show in the output: Skipped documentLink - a document has to be a direct link to a PDF or image file starting with http, or an uploaded file reference starting with doc_, and cannot contain a double quote.Show in the output: Skipped documentLink - a document has to be a direct link to a PDF or image file starting with http, or an uploaded file reference starting with doc_, and cannot contain a double quote.
No
No steps
Set runSummary to “Filed filedCount new document(s). Already in the table: skippedCount. Could not be read: failedCount.”.Set runSummary to “Filed filedCount new document(s). Already in the table: skippedCount. Could not be read: failedCount.”.
Show in the output: runSummary.Show in the output: runSummary.
If filedCount is 0 and failedCount is greater than 0If filedCount is 0 and failedCount is greater than 0
Yes
Stop and report a problem: No documents were filed and at least one could not be read. Check that the table has the columns Document, Title, Document Type, Details and Added, that your Airtable token can write to this base, and that each link serves the PDF or image itself rather than a preview page.Stop and report a problem: No documents were filed and at least one could not be read. Check that the table has the columns Document, Title, Document Type, Details and Added, that your Airtable token can write to this base, and that each link serves the PDF or image itself rather than a preview page.
No
No steps