File upload count in answer piping

Answer piping is an amazing feature! I love how it can be used everywhere - in other answers, email subjects, integrations, etc.

I also like that for addresses you can just grab part of the answer like {{ }}, etc.

Suggestion: it would be nice to have something similar for file uploads where you could just get the # of files they uploaded, i.e. {{ asdf.count }}. Then in my Google Sheet I would use conditional formatting to mark it with a red background if the count = 0, or green background if it’s > 0.

Currently, you can use calculations (Pro and Agency) to accomplish this.

When an upload question (image, file) is piped into a calculation, it is represented as the path to the file, separated by newlines, \n.

To count them, then, we could use a calculation like

if({{ uploaded_key }}, count(split({{ upload_key }}, "\n"), 0);

where upload_key is the upload question’s pre-fill key (can be found at the bottom of that question’s configuration).

First, we make sure the question is answered. This isn’t always a required step for calculations, but the answer is 1 before we even answer the question due to how our count() works. Checking if it’s answered first and providing 0 if it doesn’t alleviates this issue while still giving us the proper count when we need it.

Then, it grabs the answer from the upload question, shoves it into a list using \n as the delimiter, and then counts the number of items in the list. This, then, is equal to the number of files uploaded.

You can then use this calculation’s answer for your integration.

1 Like

That’s awesome, I wasn’t aware of calculations.

However this doesn’t seem to work, I’m just getting the literal string in my spreadsheet:

if(, count(split(), "\n"), 0);

In your statement, you’re missing any reference to a question. If you look at the statement I used in my previous message, I’m using {{ upload_key }}. You’ll need to determine the pre-fill key of your upload question and place it where I’ve placed upload_key so that it pulls that question’s answer for you to operate on.

Right, I have that in.

Screen Shot 2020-12-09 at 12.40.43 PM

(Can only attach 1 image per post)

But it doesn’t seem to be running the calculation before sending it to Google sheets

Screen Shot 2020-12-09 at 12.41.12 PM

I haven’t gotten one with actual uploads so I don’t know what that looks like yet, these ones were all empty hence why the field is just blank.

Ah, I see what’s going on. Calculations can only go into calculation questions. You then use the calculation’s answer in the mapping.

So, it’d be something like

Title: Uploaded files calculation
Key: abc123


if({{ upload_key }}, count(split({{ upload_key }}, "\n"), 0);

Then, in the mapping, you’d use

{{ abc123 }}

to pass the calculation’s value — which is our list of upload URLs — to Sheets.