首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zapier条件循环

Zapier条件循环
EN

Stack Overflow用户
提问于 2020-07-23 11:11:03
回答 1查看 138关注 0票数 0

我正在使用一些Zapier javascript从通过API返回的每日批数据构建一个数组,这样我就可以在Airtable中根据这些数据创建单独的记录。

我在这里使用了一种方法:https://community.zapier.com/tips-and-inspiration-5/how-to-repeat-action-s-in-your-zap-for-a-variable-number-of-values-3037

我的字段是: FirstName、SecondName、电子邮件和电话

代码语言:javascript
复制
/* Add as many Input Data fields as you like above as comma seperated text or mapped line items (will be 
   converted to comma seperated text). This code will find each Input Data field and output an array of 
   objects with the same structure that can be used to "Fork" the Zap. 
   Example: https://cdn.zappy.app/9de81901f3750ef26bcbbd0737b0937b.png */

// get Input Data field names
let keys = Object.keys(inputData)
let data = [];

// loop through each Input Data field
for (let key of keys) {
  // split the contents of each Input Data field on the commas into an array
  let li = inputData[key].split(",");
  for (let i=0; i<li.length; i++) {
    if (typeof data[i] === "undefined") data[i] = {};
    data[i][key] = li[i];
    // add a record number (in case we want to break the fork/loop with a Filter)
    data[i].recordNumber = i+1;
  }
}

// preview the whole data structure in the output
console.log(data);
// output the data
output = data;

我的Airtable记录需要的主要值是一个电子邮件地址,但不幸的是,它并不总是出现在来自API的源数据中。如果电子邮件值不存在,我根本不需要创建Airtable记录。

所以我想修改这个脚本,这样它就可以跳过任何记录,其中email=null

我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

发布于 2020-07-25 02:13:04

问得好!

在循环的末尾,你的变量data看起来像这样:

代码语言:javascript
复制
[{FirstName: 'Richard', SecondName: 'F', email: 'asdf@asdf.com', phone: '123...'}, ...]

然后,在将电子邮件发送到外部世界之前,您需要过滤该数组以删除任何缺少电子邮件的对象。

为此,将最后一行更改为:

代码语言:javascript
复制
output = data.filter(item => item.email)

你可以在这里尝试一下:https://runkit.com/xavdid/5f1b2445d4a368001b400372

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63046281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档