Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

creat comments when specific fields updated

Topic Labels: Automations
174 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Jason_Choi
4 - Data Explorer
4 - Data Explorer

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

2 Replies 2

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

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

Alexey_Gusev_0-1727498718007.png

 

 
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.