Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
How to output a JavaScript code in Zapier Code properly

I have a Zap that is triggered everytime a new Facebook LeadAd is generated. In the second step I created a JS code to match some fields of the leadad (Adset Name + Term) with a property of an object inside an array of objects with filter function.

Example:

let campaign = inputData.adset_name + inputData.term;

let logic = [
        {
            Campaign: "Adsetname+term",
            Doctors: "Name 1 - Name 2",
            ID: "xxxxxxxx - yyyyyyyy",
            Count: "2",
            Zone: "Neighborhood",
            UF: "City"
        }
//There's a lot of these objects inside the array with other data.
]

let filtro = logic.filter(x => {
    return x.Campaign === campaign;
});


output = [
  {
    ID: filtro.ID,
    UF: filtro.UF,
    Count: filtro.Count
  }
];

The main goal here is to match the incoming adset name + term with the adset name + term of a determined object inside the array, so it will return the other info linked to this specific object.

But the code isn't outputing any info into this object created. It runs with no errors, bur returns no data of the object.

Result of the step test

Do you know what I am doing wrong?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

In your code, filtro is set to a filtered array of objects:

filtro = [
  {ID: 'asdf', UF: 'qwer'}
]

In your output, you're accessing filtro.ID, which is undefined. An Array doesn't have an ID property.

Instead, you probably want ID, UF and Count for each item in filtro. In that case, you can use the Array.map function:

output = filtro.map(item => {
  return {
    ID: item.ID,
    UF: item.UF,
    Count: item.Count
  }
})

This will return an array of objects. If this code is an action (instead of a trigger) subsequent zap steps will run for each item you return. See these docs for more info.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!