Checks a Box folder hourly and gives each new PDF its own summary document and one row in your index sheet.
Uses
ClaudeBox
Google Docs
Google Sheets
Summarise and index new documents in a Box folder
Every hour, the Box folder you point it at is listed, the PDFs it has not read before are worked out from your own index sheet, and each new one gets a summary document in Google Docs and one row in that index. Your index sheet is the record of what has already been read.
Each summary document holds a short note saying what the document is, who it involves and any dates or amounts, followed by the exact details read out of it so you can check one against the other. The index row holds the date, the file name, the Box file id, a one-line description and a link to the summary. The note is written from those details alone, and anything not found is left blank, so it cannot assert something the document does not say. Rows are only ever added, only PDFs are read, and one file that cannot be read does not stop the rest.
Before the first run you need an index sheet with five columns: date read, file name, Box file id, what the document is, and a link to the summary.
boxFolderId to blank.Set boxFolderId to blank.indexSpreadsheetUrl to blank.Set indexSpreadsheetUrl to blank.indexSheetTabName to blank.Set indexSheetTabName to blank.maxDocumentsPerRun to 10.Set maxDocumentsPerRun to 10.boxFolderId and save it as folderId.Trim boxFolderId and save it as folderId.indexSpreadsheetUrl and save it as spreadsheetUrl.Trim indexSpreadsheetUrl and save it as spreadsheetUrl.indexSheetTabName and save it as sheetName.Trim indexSheetTabName and save it as sheetName.documentCap to maxDocumentsPerRun multiplied by 1.Set documentCap to maxDocumentsPerRun multiplied by 1.documentCap is greater than or equal to 1 is no or documentCap is less than or…If documentCap is greater than or equal to 1 is no or documentCap is less than or…alreadySummarised to an empty list.Set alreadySummarised to an empty list.ledgerErrorIf a step below fails, save the error as ledgerErrorsheetName in spreadsheetUrl. Save it as ledger.Read column 'C' of sheetName in spreadsheetUrl. Save it as ledger.ledgerValue in ledger.values:For each ledgerValue in ledger.values:ledgerValue and save it as seenId. Trim ledgerValue and save it as seenId.seenId isn't empty and seenId is not null If seenId isn't empty and seenId is not nullseenId to the end of alreadySummarised and save it as alreadySummarised.Add seenId to the end of alreadySummarised and save it as alreadySummarised.ledgerError.message.Stop and report a problem: Could not read column C of the index sheet, which is the only record of what has already been read - so nothing has been touched. Check the 'indexSpreadsheetUrl' and 'indexSheetTabName' steps. The reason given was: ledgerError.message.folderItems to an empty list.Set folderItems to an empty list.folderErrorIf a step below fails, save the error as folderErrorfolderId. Save it as folder.List items in Box folder folderId. Save it as folder.folderItems to folder.items.Change folderItems to folder.items.folderError.message.Stop and report a problem: Could not list that Box folder, so nothing has been read. Check the id in the 'boxFolderId' step. The reason given was: folderError.message.summarisedCount to 0.Set summarisedCount to 0.alreadyDoneCount to 0.Set alreadyDoneCount to 0.notADocumentCount to 0.Set notADocumentCount to 0.failedCount to 0.Set failedCount to 0.readOn.Trim today's date and save it as readOn.item in folderItems:For each item in folderItems:summarisedCount is greater than or equal to documentCapIf summarisedCount is greater than or equal to documentCapsummarisedCount document(s). The rest of the folder is picked up on the next run.Show in the output: Stopped after summarisedCount document(s). The rest of the folder is picked up on the next run.itemType to blank.Set itemType to blank.itemTypeErrorIf a step below fails, save the error as itemTypeErroritem.type and save it as itemType.Trim item.type and save it as itemType.itemType to blank.Change itemType to blank.itemType is not fileIf itemType is not filefileName to blank.Set fileName to blank.fileNameErrorIf a step below fails, save the error as fileNameErroritem.name and save it as fileName.Trim item.name and save it as fileName.fileName to blank.Change fileName to blank.item.id and save it as fileId.Trim item.id and save it as fileId.fileName is empty or fileId is empty or fileId is nullIf fileName is empty or fileId is empty or fileId is nullSkipped an item in the folder because Box gave it no usable name or id..Show in the output: Skipped an item in the folder because Box gave it no usable name or id..alreadySummarised contains fileIdIf alreadySummarised contains fileIdalreadyDoneCount.Add 1 to alreadyDoneCount.fileName doesn't end with .pdf (ignoring case)If fileName doesn't end with .pdf (ignoring case)notADocumentCount.Add 1 to notADocumentCount.fileName.Show in the output: Left alone because it is not a PDF: fileName.documentErrorIf a step below fails, save the error as documentErrorfileId. Save it as download.Download file fileId. Save it as download.download.document_ref and save it as documentRef.Trim download.document_ref and save it as documentRef.extraction.Run an AI agent: Read the attached document and pull out each of these fields, in this order: - Document t… and save it as extraction.detailLines to an empty list.Set detailLines to an empty list.documentTitle to blank.Set documentTitle to blank.extractedField in extraction.output.fields:For each extractedField in extraction.output.fields:fieldName to blank. Set fieldName to blank.fieldNameError If a step below fails, save the error as fieldNameErrorextractedField.name and save it as fieldName.Trim extractedField.name and save it as fieldName.fieldName to blank.Change fieldName to blank.fieldName isn't empty If fieldName isn't emptyfieldValue to blank.Set fieldValue to blank.fieldValueErrorIf a step below fails, save the error as fieldValueErrorextractedField.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.fieldValue isn't emptyIf fieldValue isn't emptyfieldName: fieldValue to the end of detailLines and save it as detailLines.Add fieldName: fieldValue to the end of detailLines and save it as detailLines.fieldName is Document titleIf fieldName is Document titledocumentTitle to fieldValue.Change documentTitle to fieldValue.detailLines with a new line and save it as detailBlock.Join detailLines with a new line and save it as detailBlock.detailBlock is emptyIf detailBlock is emptyfailedCount.Add 1 to failedCount.fileName, so it has been left for you to look at. Nothing was written.Show in the output: Nothing could be read out of fileName, so it has been left for you to look at. Nothing was written.summaryText to blank.Set summaryText to blank.summaryErrorIf a step below fails, save the error as summaryErrordetailBlock'. Save it as summaryReply.
Maximum response length: 700summaryReply.response_text and save it as summaryText.Trim summaryReply.response_text and save it as summaryText.summaryText to blank.Change summaryText to blank.summaryText is emptyIf summaryText is emptysummaryText to No written note came back for this document. The details read out of it are below, unchanged..Change summaryText to No written note came back for this document. The details read out of it are below, unchanged..summaryText split by a new line and save it as headline.Trim the first item of summaryText split by a new line and save it as headline.documentName to documentTitle.Set documentName to documentTitle.documentName is emptyIf documentName is emptydocumentName to fileName.Change documentName to fileName.headline is emptyIf headline is emptyheadline to documentName.Change headline to documentName.summaryDocumentId.Trim the document id from the Google Docs “Create document” step and save it as summaryDocumentId.documentName to summaryDocumentId.Add the heading documentName to summaryDocumentId.summaryDocumentId.Add text to summaryDocumentId.summaryText
Read word for word from the document:
detailBlock
Source file: fileName (Box file fileId), read on readOn.sheetName in spreadsheetUrl.Add a row to sheetName in spreadsheetUrl.summarisedCount.Add 1 to summarisedCount.failedCount.Add 1 to failedCount.fileName, so it has been left alone and will be tried again next run: documentError.message.Show in the output: Could not read fileName, so it has been left alone and will be tried again next run: documentError.message.summarisedCount new document(s). Already indexed: alreadyDoneCount. Not a PDF: notADocumentCount. Could not be read: failedCount.Show in the output: Read and indexed summarisedCount new document(s). Already indexed: alreadyDoneCount. Not a PDF: notADocumentCount. Could not be read: failedCount.