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
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…Yes
No
No steps
alreadySummarised to an empty list.Set alreadySummarised to an empty list.ledgerErrorIf a step below fails, save the error as ledgerErrorTry
sheetName 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 nullYes
seenId to the end of alreadySummarised and save it as alreadySummarised.Add seenId to the end of alreadySummarised and save it as alreadySummarised.No
No steps
On error
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 folderErrorTry
folderId. Save it as folder.List items in Box folder folderId. Save it as folder.folderItems to folder.items.Change folderItems to folder.items.On error
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 documentCapYes
summarisedCount 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.No
No steps
itemType to blank.Set itemType to blank.itemTypeErrorIf a step below fails, save the error as itemTypeErrorTry
item.type and save it as itemType.Trim item.type and save it as itemType.On error
itemType to blank.Change itemType to blank.itemType is not fileIf itemType is not fileYes
No
No steps
fileName to blank.Set fileName to blank.fileNameErrorIf a step below fails, save the error as fileNameErrorTry
item.name and save it as fileName.Trim item.name and save it as fileName.On error
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 nullYes
Skipped 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..No
No steps
alreadySummarised contains fileIdIf alreadySummarised contains fileIdYes
alreadyDoneCount.Add 1 to alreadyDoneCount.No
No steps
fileName doesn't end with .pdf (ignoring case)If fileName doesn't end with .pdf (ignoring case)Yes
notADocumentCount.Add 1 to notADocumentCount.fileName.Show in the output: Left alone because it is not a PDF: fileName.No
No steps
documentErrorIf a step below fails, save the error as documentErrorTry
fileId. 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 fieldNameErrorTry
extractedField.name and save it as fieldName.Trim extractedField.name and save it as fieldName.On error
fieldName to blank.Change fieldName to blank.fieldName isn't empty If fieldName isn't emptyYes
fieldValue to blank.Set fieldValue to blank.fieldValueErrorIf a step below fails, save the error as fieldValueErrorTry
extractedField.value and save it as fieldValue.Trim extractedField.value and save it as fieldValue.On error
extractedField.value with ; and save it as fieldValue.Join extractedField.value with ; and save it as fieldValue.fieldValue isn't emptyIf fieldValue isn't emptyYes
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.fieldName is Document titleIf fieldName is Document titleYes
documentTitle to fieldValue.Change documentTitle to fieldValue.No
No steps
No
No steps
No
No steps
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 emptyYes
failedCount.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.No
summaryText to blank.Set summaryText to blank.summaryErrorIf a step below fails, save the error as summaryErrorTry
detailBlock'. Save it as summaryReply.
Maximum response length: 700summaryReply.response_text and save it as summaryText.Trim summaryReply.response_text and save it as summaryText.On error
summaryText to blank.Change summaryText to blank.summaryText is emptyIf summaryText is emptyYes
summaryText 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..No
No steps
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 emptyYes
documentName to fileName.Change documentName to fileName.No
No steps
headline is emptyIf headline is emptyYes
headline to documentName.Change headline to documentName.No
No steps
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.On error
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.