Skip to main content

creat comments when specific fields updated

  • September 26, 2024
  • 2 replies
  • 2 views

Forum|alt.badge.img+4

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

TheTimeSavingCo
Forum|alt.badge.img+28

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


Alexey_Gusev
Forum|alt.badge.img+23
  • Brainy
  • 1145 replies
  • September 28, 2024

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.


Reply