Sep 26, 2024 12:24 AM
I'm using automation.
I want to automatically add comments to the record when updating certain fields, but I can't..
What should I do
And. I keep failing to get records... I caught when record updated with trigger...
let table = base.getTable("Your Table Name");
let recordId = input.config().recordId;
if (!recordId) {
throw new Error("Record ID가 정의되지 않았습니다.");
}
let record = await table.selectRecordAsync(recordId);
let fields = ["fields1, fields2, fields3"];
let changes = [];
for (let field of fields) {
let oldValue = record.getCellValue(field); //
let newValue = record.getCellValue(field); /
if (oldValue !== newValue) {
changes.push(`${field} 값이 ${oldValue}에서 ${newValue}로 변경되었습니다.`);
}
}
if (changes.length > 0) {
output.set("changes", changes.join("\n"));
}
[Error]
ERROR
TypeError: Invalid arguments passed to table.selectRecordAsync(recordId, options):
• recordId should be a string, not undefined
at main on line 7
Sep 26, 2024 02:34 AM
I believe you'll need to use the web API to create comments: https://airtable.com/developers/web/api/create-comment
This might be a tricky process if you're not already familiar with JavaScript, so I'd suggest asking someone you know who's familiar with JavaScript to help you with this
Sep 27, 2024 09:52 PM
input.config() is an object that holds all variables you are defined on a left side of automation script editor. You can put trigger record ID there
As I remember, automation cannot work with comments.
But the main flaw of your script - you can't receive old values
once trigger worked, it means changed are made.
you can add hidden fields for old values, like 'oldfields1', 'oldfields2'.....
and do
let oldValue = record.getCellValue('old'+field); //
let newValue = record.getCellValue(field); //
and somewhere at the end of automation you should copy values from current fields to old. It's just a singe Update step for all 3 fields.