Skip to main content

I created a long zap with various steps. Some of them include some Javascript “Code by Zapier” steps.

The inputData is the result of a Snowflake SQL query, so sometimes it returned 0 result.

Because of that, as I was iterating the results, it was throwing the dreaded “TypeError: Cannot read property 'trim' of undefined”.

I wanted to fix that by creating a logic to check the data and stop the script. See below:

// Catch empty data and return empty value
if (
!inputData ||
!inputData.dates ||
!inputData.integrations ||
!inputData.counts
) {
console.error(
"Missing or empty inputData properties. Cannot create the chart."
);
output = { url: "Not enough data" };
return output;
}

(note that I need to return something or the step fails)

Now the strangest thing happened:

  1. The test of the zap shows no issue if there’s correct inputData or not
  2. In production, when testing the complete zap, there’s still the “TypeError: Cannot read property 'trim' of undefined” with correct data
  3. As a consequence, the last steps are skipped, and I can’t find a way to avoid that

I made sure:

  • the history showed the last version of my code
  • the variable names are correct
  • the inputData was correct

I also contacted Support who were not able to help (so far).

We’re a paying customer for a long time, and I don’t know what to do to fix it.

Hi @timleroy 

Good question.

Have you tried asking ChatGPT for help with the JavaScript code?

We would need to see how your full JavaScript code step is configured along with screenshots of the Zap Runs DATA IN and the encountered error.


Support loves to use this solution first 😁 

Actually the issue was in my query with various lengths of data. I changed both and it’s now working!

As I wrote to Support, there’s 2 things to enhance the experience:

  1. Get a line number in the error message, to help devs to debug
  2. Set a step as mandatory to effectively skip some further steps if necessary, otherwise perform all steps

The latter is important imo, because in my case, I had all steps but one out of 70+ that was blocking my zap.

Thanks!


Hi @timleroy 

Best to share feedback and feature requests via a ticket to Zapier Support so it is properly logged: https://zapier.com/app/get-help


Reply