Best answer

Can I get the inputData with empty string


Userlevel 1

I guess I hit a bug of Zapier.

 

In one zapier step, it returns a set of data (as an array in a output object)

 

In the JavaScript code block, I can define a variable, and map it to the object

 

The problem is when I was in the code editor page, I can preview the value as ,,,,,,7,,8,

but in the code, if I ran console.log to debug, I found this inputData became 7,8, all those empty string is removed. As a result, when I run inputData.abc.split(‘,’), I got unexpected results.

 

Can you confirm whether this is a bug or any workaround?

 

 

icon

Best answer by Troy Tessalone 13 March 2024, 03:16

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

10 replies

Userlevel 7
Badge +14

Hi @jove 

Help articles for using Code: https://zapier.com/apps/code/help

Help articles for handling line items:

 

Userlevel 1

Thanks Troy for looking into this. But the link you shared doesn’t really help.

 

My previous step is GetCustomers from Paigo. It reports a list of customers.

 

The bug of Zapier is when I define an inputData, it shows previews as ,,,,,,7,,8, (this is correct)

But in the JavaScript code, I use console.log to show the inputData.xyz, it became 7,8

the empty values are removed. So after I split it, I got 2 elements, instead of many elements with some empty string. I have a few such attributes. Each inputData has different length, depending on whether the data can be empty.

 

This blocks me.

Userlevel 7
Badge +14

@jove 

For us to have full context, we would need to see screenshots with how the Zap steps are outlined and configured along the the structure of the data points from their origin step that you are trying to use as inputData in the Code step.

 

Userlevel 1

Sure, let me post a few screenshot (sensitive customer info are masked)

 

Step 1 is a webhook or cron job. Step 2 is to Get Customers from Paigo. Step 3 is JS code. Step 4 is Slack DM

 

In the Code by Zapier, you see I defined a few inputData, for example the freeTrialEndDate is a set of date, with many empty string (this is expected)

 

I also showed the first 2 lines of the JS code, with a console log. What is clearly wrong is the string I printed has all empty parts removed.

This is not the data I got in the 1st screenshot.

 

This issue only happens when there are empty strings in the previous step. I cannot customize the previous step. So I hope Code By Zapier can keep the raw array(or a string representation). I didn’t test the Python part, but prefer not rewriting this JS code to Python.

Userlevel 7
Badge +14

@jove 

As an example, post screenshots with how the data is returned from Step 2 so we’re able to see the true structure of the data before it’s used in the Code step.

 

Userlevel 7
Badge +14

@jove 

A possible workaround:

Zap Action: Formatter > Utilities > Line Items to Text

 

 

EXAMPLE

Origin array data

 

When you configure like this...

 

You get these results…

Then you can pass in the Output Text and handle it however you want in the Code step.

Adjust as needed.

 

Userlevel 1

Thanks for sharing the workaround. I may try this later.

 

Here is the screenshot of Step 2

I think data is a big array. Each object has a lot of attribute, but not all attributes has the freeTrailEndDate field.  I think there are some inconsistency in Zapier:

  • in the input data define page, the data preview is correct. with a set of ,,,,
  • while in the code (AWS Lambda?) the input object has no empty parts

I can try the formatter utility for sure, but prefer this issue is confirmed and fixed by Zapier team.

Userlevel 7
Badge +14

@jove 

I don’t think this is a “bug” per se, rather a limitation with how the data is formatted (array of objects), which can make it trickier to deal with across Zap steps.

 

You can submit feedback via a ticket to Zapier Support to be logged: https://zapier.com/app/get-help

 

I wouldn’t expect any change to happen any time soon related to the Code step.

Userlevel 7
Badge +14

@jove 

More context about Code step form the Input Data field description and help articles: https://zapier.com/apps/code/help

 

Since the Input Data values get treated as strings, an array with leading/trailing empty indexes essentially gets trimmed when converted to a string.

 

 

Userlevel 1

I have implemented the workaround you mentioned. Yes, it does work. But I need to run substr(1) to remove the prefix.

 

I am a software developer and understands the string, but I still think it’s a bug. In a single Code block step, the preview data and the real data are not the same.