我正在使用一些Zapier javascript从通过API返回的每日批数据构建一个数组,这样我就可以在Airtable中根据这些数据创建单独的记录。
我的字段是: FirstName、SecondName、电子邮件和电话
/* 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
我怎样才能做到这一点呢?
发布于 2020-07-24 18:13:04
问得好!
在循环的末尾,你的变量data
看起来像这样:
[{FirstName: 'Richard', SecondName: 'F', email: 'asdf@asdf.com', phone: '123...'}, ...]
然后,在将电子邮件发送到外部世界之前,您需要过滤该数组以删除任何缺少电子邮件的对象。
为此,将最后一行更改为:
output = data.filter(item => item.email)
你可以在这里尝试一下:https://runkit.com/xavdid/5f1b2445d4a368001b400372
https://stackoverflow.com/questions/63046281
复制相似问题