Extracting information of multiple pdf's

Describe the problem/error/question - I have built a workflow that looks at my email if its a PDF it will extract the infromation and append to a google sheet. I simply want to account for the case where there is multiple PDFs, in the code block I have set it up as such
const items = ;
for (const inputItem of $items()) {
const binary = inputItem.binary || {};
const json = inputItem.json || {};
for (const [key, value] of Object.entries(binary)) {
if (value.fileExtension === ‘pdf’) {
items.push({
json: {
attachment_key: key,
dedupe_key: ${json.id}_${key},
fileType: value.fileType,
fileExtension: value.fileExtension,
},
binary: {
[key]: value
}
});
}
}
if (Object.keys(binary).length === 0) {
items.push({ json: { notice: ‘no PDFs found’ } });
}
}
return items;
to seperate the items ensuring that binary file is being outputted .I then split based on attachment_key, check if it is a PDF then through a dedupe_key check if it exists in the google sheet if it doesn’t I append it ensuring that i do not upload the same emails into the google sheet. Now when I reach the append stage all of the values say “[Can’t determine which item to use]”. I’m not sure why as I thought I have split it already and cannot use “{{ $json.headers.from }}” as my previous statement is an if statement checking for duplicates. Would appreciate your insight on how to solve this! Thanks!

What is the error message (if any)? [Can’t determine which item to use]

Please share your workflow

Share the output returned by the last node

[Can’t determine which item to use] / ExpressionError: Multiple matches found at createExpressionError (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-workflow@file+packages+workflow/node_modules/n8n-workflow/src/workflow-data-proxy.ts:790:11) at createPairedItemMultipleItemsFound

Information on your n8n setup

  • n8n version:2.1.5
  • Database (default: SQLite): GoogleSheets
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8ncloud
  • Operating system:MacOS Sequoia 15.6.1

Hi @Zafeer,

Since your code node is already filtering out the pdf files, you dont need the if node down the line. All you have to do now is enter a Loop node and then process it fine by file.

See the below example, where I used a form submit for now to avoid gmail setup, but it functions the same when handing multiple binary files.

The Loop node allows you to loop over each attachment and process each file one by one

2 Likes

hello! ill try to implement that, i have the if statement because even if there is no pdf in the email. I still want the body of the email to be added to the google sheet. I believe i can add the loop after the if statement and it should work ill try it and let you know!

1 Like

added this after the if it worked thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.