- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 01, 2023 06:54 AM
Hello everyone!
I have this script:
const tableId = "tblapiXxSQL4FGs7G";
const table = base.getTable(tableId);
const viewId = "viwVt3r8YFoHt5sy6";
const view = table.getView(viewId);
const records = await view.selectRecordsAsync();
const filteredRecords = records.records.filter(record => {
return record.getCellValue("View") === viewId;
});
const updatedRecords = filteredRecords.map(record => {
return {
id: record.id,
fields: {
"fldOhTCFbOqx05nxk": "",
"fldDCytU41W6YcJQu": ""
}
};
});
if (updatedRecords.length > 0) {
await table.updateRecordsAsync(updatedRecords);
console.log(`Updated ${updatedRecords.length} records.`);
} else {
console.log("No records to update.");
}
The purpose with the script is to have certain fields cleared for value when x conditions are met. It works like a charm in other tables, but in my newly created table it just won't work. I have inserted the correct IDs (table, view and fields), but the error I get is this:
at <anonymous> on line 9 at main on line 8
As mentioned it's the exact same script used in other tables, and those tables does not have a field named 'View' either, so why does it suddenly want a field named 'View'?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 01, 2023 07:52 AM - edited ‎Apr 01, 2023 07:55 AM
Hi
const filteredRecords = records.records.filter(record => {
return record.getCellValue("View") === viewId;
});
getCellValue returns record value at some field, so you should put field name here.
also, it seems like your filter will return empty array, I doubt you store viewID as values in table
idk why do you use IDs instead of names, but unless you have special reason for that, it just a way to add complexity to a simple thing ))

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 01, 2023 08:14 AM
Sometimes people use IDs instead of names so that the script will still work even if the table and field names change.
However, I agree that using table, view, and field IDs without some other method of indicating the intended items can be confusing.
Note that this script will also have problems if there are ever more than 50 records to update (once the filtering issue is sorted out).
I also find some of the variable names slightly confusing/misleading: records, and updatedRecords.
