Slowly piecing together a Regex script in the Scripting App, but I’m stuck with table.updateRecordAsync not reading the field that’s active in the loop. If I hard-code the field name in with quotes it then works as I hoped, but if I use the field.name from the loop, it won’t parse.
So the below works (but isn’t very useful as I’m trying to cycle through fields rather than hardcode a string);
await table.updateRecordAsync(record, {"
Test_1": String("test1")});
“test1” will successfully write to each record for field “ Test_1”. But when I swap out the hardcoded Field name string with field.name it unfortunately fails to parse.
await table.updateRecordAsync(record, {field.name: String("test2")});
Running Console log on field.name, it comes up as expected - so I’m not too sure what I’m doing wrong and will appreciate some help. Full code below - and keep in mind that I’m still learning Javascript - I’m finding it tricky to break my old coding method and habits to learn the new techniques that Javascript keeps throwing me - but practice makes perfect… just wish I wasn’t being stumped on something that’s probably overly simple… but I can’t get it cracked. >_<
let table = base.getTable("Log Files");
// query for all the records in a table
let queryResult = await table.selectRecordsAsync({
sorts: R
{field: "Log File Name"},
]
});
//Cycles through each record
for (let record of queryResult.records) {
output.markdown(`**${record.getCellValueAsString("Log File Name")}** - ${record.id}`);
//Cycles through each field and looks for
prefix
for (let field of table.fields) {
if (field.name.includes("
")) {
output.text(`${record.getCellValueAsString(field)}`)
console.log(field.name)
console.log(field)
await table.updateRecordAsync(record, {"
Test_1": String("test1")});
await table.updateRecordAsync(record, {field.name: String("test2")}); //this line won't execute?
output.text(`${record.getCellValueAsString(field)}`)
}
}
}
Further to this, I’m wanting my Script to handle dynamic changing field names, and only process any field with a prefix, but I think the fact that table.selectRecordsAsync is insisting I type all field names of interest in, I’m worried I might be on borrowed time before it’s depreciated? How can I code await table.selectRecordsAsync to happily process all fields within my table without writing their names out?
The below will clear the strike through, but defeats the purpose/goals of having my code loop through to find the fields of interest.
let queryResult = await table.selectRecordsAsync({
fields : ="Log File Name", "Log Content","
Test_1", "
Test_a"],
sorts: "
{field: "Log File Name"}
]
});