Best answer

Unable to "Find a single item in an array, output corresponding field"

  • 23 June 2022
  • 8 replies
  • 145 views

Userlevel 1
Badge

I was following the great article over at 

when I ran into trouble. After following the instructions EXACTLY and even reaching out to the author, I simply cannot get the correct output. I’ve been able to confirm that the incoming info for the step “Run Javascript in Code by Zapier” matches the format shown in the original author’s writeup but the output always fails to return the expected data.

I followed the directions from the article but my output does NOT return the value. In fact, I don't have any output other than the id of the code step and a couple items for "runtime_meta". The links below are screenshots of the Code setup, Test Parameters (had to snag it quick) and the Output.

 

Code Setup step
https://www.awesomescreenshot.com/image/27853177?key=18d81e5faa769e0766cd535f28b547f9

 

Test Parameters (what shows briefly when testing the step)
https://www.awesomescreenshot.com/image/27853176?key=8e64b2a0846ef888ad497b9f28a6244f

 

Output
https://www.awesomescreenshot.com/image/27853175?key=70ffffe09f4ff1d597a7e1663d7418d5

 

Data step: https://www.awesomescreenshot.com/image/28088662?key=0f22c29f04a73f1888171016ce100df1

 

Insert Data options: https://www.awesomescreenshot.com/image/28088847?key=0a11460cf4482aec9b071cf2769f5bb0

The data step indicates I have the same structure as the original example but when I'm inserting the data into the Input Data fields it shows 3. Primary and 3. Number instead of the original which I'd expect to then show:

phone_numbers[]principal
phone_numbers[]address

 

@nicksimard suggested I post this in the community so maybe we could figure this out. His article/how-to is fantastic and I want to be able to use this.

icon

Best answer by shawnrosspeters 23 June 2022, 23:05

View original

8 replies

Userlevel 7
Badge +14

Hi @shawnrosspeters 

Good question.

Try this…

Change the output to this to include the opening/closing brackets []

output = [{id: ids[index]}];

 

 

Userlevel 1
Badge

Hi @shawnrosspeters 

Good question.

Try this…

Change the output to this to include the opening/closing brackets []

output = [{id: ids[index]}];

 

 

Thanks @Troy Tessalone but that didn’t work either. I still just get an ID number of some kind and some metadata when I “Retest & review”

 

Userlevel 7
Badge +14

@shawnrosspeters 

We’d need to have you paste your exact code and inputs in order to troubleshoot further.

 

I tested this

 

Which returned this…

 

Userlevel 1
Badge

@Troy Tessalone

I’ve copied and pasted everything. I only changed the phone numbers so my real numbers aren’t exposed publicly.

Input Data

names

3. Primary:true,false

ids

3. Number:8305551234,8305555678

username

true

Code

const names = inputData.names.split(",");

const ids = inputData.ids.split(",");

const index = names.findIndex(name => name.includes(inputData.username));

output = [{id: ids[index]}];

 

Userlevel 1
Badge

@Troy Tessalone sorry. I had to edit the post afterward. Weird glitch, lol.

Userlevel 7
Badge +14

@shawnrosspeters 

It worked for me.

 

CONFIG

 

RESULTS

 

Userlevel 1
Badge

I finally figured this out and got it to work!

TL;DR

The search variable (in this case “username”) is case-sensitive. If you're attempting this same How-To and your code Output isn’t working as expected then record the “Test Action” in a screen recording. This will let you slow it down to see if the data being processed actually matches what you think it should be or not. In my case, I thought everything was lowercase when in reality it was Capitalized.

 

The good news is that the square brackets (i.e. [ ]) are not needed nor were they causing the problem.

I first tested by manually inputting the key|value pairs, just like your last comment, and it worked when I tested the action. However, it STILL didn’t work when actually using the dynamic values generated in Step #3 from the Zap.

I then edited a short screen recording so I could show you the discrepancies when I noticed for a fraction of a second the “processing test” portion of the manually entered values. I’m including links below.

Manually Entered key|value pairs

Using variables from previous step

Screenshot of variables in “Set up action”

The issue is that the “username” key was looking for “true” in all lowercase but my dynamic values from Step #3 were ACTUALLY being pushed through capitalized, i.e. “True” instead of “true”. What stumped me was that the Step #3 variables show as all lowercase when you’re viewing the “Set up action” portion of the Code Step. Even though these are actually pushed through in the code step as Capitalized.

So, thank you @Troy Tessalone for your help in narrowing this down and thank you @nicksimard for the original article and initial support! Maybe you can add a “FAQ” or “Common Problems” to your article over at 

😎

Userlevel 7
Badge +9

@shawnrosspeters Woohoo! This is great! I am so glad you and Troy were able to work through this one and super grateful for you coming back to this thread to share your solution with us! What a lovely team effort. 🙂

Reply