PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 15, 2022

[FIXED] How to output a JavaScript code in Zapier Code properly

 August 15, 2022     arrays, javascript, output, zapier     No comments   

Issue

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?


Solution

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.



Answered By - xavdid
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing