Reads each document you link, pulls out the details you asked for, and adds one Airtable record per document.
Uses
Airtable
OpenAI
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.
documentLinks to blank.Set documentLinks to blank.detailsToPullOut to blank.Set detailsToPullOut to blank.airtableBaseId to blank.Set airtableBaseId to blank.airtableTableName to blank.Set airtableTableName to blank.maxDocuments to 25.Set maxDocuments to 25.airtableBaseId and save it as baseId.Trim airtableBaseId and save it as baseId.airtableTableName and save it as tableName.Trim airtableTableName and save it as tableName.detailFieldNames to an empty list.Set detailFieldNames to an empty list.detailEntry in detailsToPullOut with "For each detailEntry in detailsToPullOut with
replaced by , split by ,:detailEntry and save it as detailName.Trim detailEntry and save it as detailName.detailName isn't emptyIf detailName isn't emptydetailName to the end of detailFieldNames and save it as detailFieldNames.Add detailName to the end of detailFieldNames and save it as detailFieldNames.detailFieldNames is emptyIf detailFieldNames is emptyTitle, 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.addedOn.Get today's date and save it as addedOn.documentsRead to 0.Set documentsRead to 0.filedCount to 0.Set filedCount to 0.skippedCount to 0.Set skippedCount to 0.failedCount to 0.Set failedCount to 0.documentEntry in documentLinks with "For each documentEntry in documentLinks with
replaced by , split by ,:documentsRead is greater than or equal to maxDocumentsIf documentsRead is greater than or equal to maxDocumentsdocumentsRead 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.documentEntry and save it as documentLink.Trim documentEntry and save it as documentLink.documentLink isn't emptyIf documentLink isn't emptydocumentsRead.Add 1 to documentsRead.documentLink starts with http (ignoring case) or documentLink starts with…If documentLink starts with http (ignoring case) or documentLink starts with…documentErrorIf a step below fails, save the error as documentErrortableName. Save it as alreadyFiled.List records in tableName. Save it as alreadyFiled.alreadyFiled.records isn't emptyIf alreadyFiled.records isn't emptyskippedCount.Add 1 to skippedCount.documentLink.Show in the output: Already in the table, left alone: documentLink.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.extractedFields to extraction.output.fields.Set extractedFields to extraction.output.fields.documentTitle to blank.Set documentTitle to blank.documentType to blank.Set documentType to blank.detailLines to an empty list.Set detailLines to an empty list.extractedField in extractedFields:For each extractedField in extractedFields:extractedField.name and save it as fieldName. Trim extractedField.name and save it as fieldName.fieldValue to blank. Set fieldValue to blank.fieldIsAList If a step below fails, save the error as fieldIsAListextractedField.value and save it as fieldValue.Trim extractedField.value and save it as fieldValue.extractedField.value with , and save it as fieldValue.Join extractedField.value with , and save it as fieldValue.fieldName is Title If fieldName is TitledocumentTitle to fieldValue.Change documentTitle to fieldValue.fieldName is Document Type If fieldName is Document TypedocumentType to fieldValue.Change documentType to fieldValue.Title, Document Type] doesn't contain fieldName If [Title, Document Type] doesn't contain fieldNamefieldName: fieldValue to the end of detailLines and save it as detailLines.Add fieldName: fieldValue to the end of detailLines and save it as detailLines.recordTitle to documentTitle.Set recordTitle to documentTitle.recordTitle is emptyIf recordTitle is emptyrecordTitle to documentLink.Change recordTitle to documentLink.tableName.Add a record to tableName.filedCount.Add 1 to filedCount.failedCount.Add 1 to failedCount.documentLink: documentError.message.Show in the output: Could not file documentLink: documentError.message.failedCount.Add 1 to failedCount.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.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.runSummary.Show in the output: runSummary.filedCount is 0 and failedCount is greater than 0If filedCount is 0 and failedCount is greater than 0