英文:
Creating Multiple Records in Airtable using Form and Script
问题
我正在尝试创建一个在Airtable中的脚本,该脚本可以从表单中接收用户输入,并创建多个记录。输入包括付款数量、第一笔付款日期、频率(我们现在可以假设为每月一次),以及付款金额。以下是我目前的代码。我收到了一个错误,指示所有输入上不存在属性'numberAsync',类型为'{ config(): {}; }'。
// 从表单获取要创建的记录数量
let numRecords = input.numberAsync('Number of Payments');
// 从表单获取截止日期
let dueDate = input.dateAsync('Due Date');
// 从表单获取付款金额
let paymentAmount = input.numberAsync('Payment');
// 创建一个循环来创建指定数量的记录
let i = 1;
while (i <= numRecords) {
// 使用当前的i值、dueDate和paymentAmount创建新记录
createRecord(i, dueDate, paymentAmount);
// 增加i的值
i++;
}
请检查您的代码,确保输入的字段名称与您的表单匹配,并确保您的Airtable脚本配置正确。如果您仍然遇到问题,请提供更多详细信息,以便我能够帮助您更好地解决问题。
英文:
I'm trying to create a script in airtable that takes user input from a form and creates multiple records. The inputs are the number of payments, date of first payment, frequency (we can just assume monthly now), and the payment amount. Here is the code that I have so far. I'm getting an error that Property 'numberAsync' does not exist on type '{ config(): {}; }' for all of my inputs.
// Get the number of records to create from the form
let numRecords = input.numberAsync('Number of Payments');
// Get the due date from the form
let dueDate = input.dateAsync('Due Date');
// Get the payment amount from the form
let paymentAmount = input.numberAsync('Payment');
// Create a while loop to create the specified number of records
let i = 1;
while (i <= numRecords) {
// Create a new record with the current value of i, dueDate, and paymentAmount
createRecord(i, dueDate, paymentAmount);
// Increment i
i++;
}
答案1
得分: 1
你遇到的错误是由于你尝试检索 input
的方式导致的。numberAsync
、dateAsync
和其他类似的函数不支持在Airtable脚本中使用。
你从哪里获取了你的脚本?我在Airtable文档中找不到任何提到你提到的函数的参考。
相反,你应该使用 input.config()
函数,正如 airtable
文档建议的那样,在运行脚本时提示用户输入。以下是如何修改你的脚本以实现你的目标:
let config = input.config({
title: 'Create Multiple Records',
description: 'Enter the details for creating multiple records:',
items: [
{ type: 'number', name: 'numRecords', label: 'Number of Payments' },
{ type: 'date', name: 'dueDate', label: 'Due Date' },
{ type: 'number', name: 'paymentAmount', label: 'Payment Amount' }
]
});
let numRecords = config.numRecords;
let dueDate = config.dueDate;
let paymentAmount = config.paymentAmount;
let i = 1;
while (i <= numRecords) {
createRecord(i, dueDate, paymentAmount);
// Increment i
i++;
}
// Function to create a new record
function createRecord(index, dueDate, amount) {
// 在这里添加在Airtable中创建新记录的逻辑
// 例如:
table.createRecordAsync({
'Due Date': dueDate,
'Payment Amount': amount
});
}
我没有测试过这段代码。它只是反映了这个想法。如果你需要在你的代码中的其他地方访问这些值的函数,你可以将这个逻辑封装在一个类中,并创建getter函数。
然而,如果你绝对需要在输入中使用你提到的函数,你可以扩展输入的原型。你应该能够在互联网上找到一些相关的信息。然而,这是极不推荐的。
英文:
The error you're encountering is due to how you're trying to retrieve input
. The numberAsync, dateAsync, and other similar functions aren't supported for scripting in Airtable.
Where did you get your script? I can't find any reference to your mentioned functions in the Airtable documentation.
Instead, you should use the input.config()
function as the airtable
documentation suggests, to prompt for input when running a script. Here's how you can modify your script to achieve your goal:
let config = input.config({
title: 'Create Multiple Records',
description: 'Enter the details for creating multiple records:',
items: [
{ type: 'number', name: 'numRecords', label: 'Number of Payments' },
{ type: 'date', name: 'dueDate', label: 'Due Date' },
{ type: 'number', name: 'paymentAmount', label: 'Payment Amount' }
]
});
let numRecords = config.numRecords;
let dueDate = config.dueDate;
let paymentAmount = config.paymentAmount;
let i = 1;
while (i <= numRecords) {
createRecord(i, dueDate, paymentAmount);
// Increment i
i++;
}
// Function to create a new record
function createRecord(index, dueDate, amount) {
// Your logic to create a new record in Airtable goes here
// For example:
table.createRecordAsync({
'Due Date': dueDate,
'Payment Amount': amount
});
}
I have not tested the code. It should just reflect the idea. If you need functions that access these values somewhere else in your code, you can wrap this logic in a class and create getter functions.
However, if you absolutely need the functions you mentioned on the input, you can extend the prototype of the input. You should be able to find some stuff on the internet about this. However, this is highly not recommended.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论