It’s not often that a new user posts here asking for help in such a pleasantly verbose manner.
And the few that do tend to be at least knee-deep in the need-work-for-hire category, knowingly or not.
But you, @Dave_Sheppard? You’re as unicorny as Airtable itself.
So here, welcome to the community:
Click for welcomeness
let table = base.getTable('Table 1'),
q = await table.selectRecordsAsync(
{
sorts: [{ field: 'ID', direction: 'desc' }],
fields: ['Done']
}),
latestRecord = q.recordIds[0],
cache = []
q.records.forEach(
rec => {
let mark = rec.id === latestRecord ? true : null
if (rec.getCellValue('Done') !== mark) {
cache.push({ id: rec.id, fields: { Done: mark } })
}
})
let neededUpdating = [...cache = cache.filter(obj => obj !== null)]
while (cache.length > 0) {
await table.updateRecordsAsync(cache.splice(0, 50))
}
output.markdown(`
| | |
|:---------------------|----------------------------:|
| Records checked | ${q.recordIds.length} |
| Records updated | ${neededUpdating.length} |
`)
The eccentric code style is a combination of the following factors:
a) I needed a coding distraction from coding
b) It meshes well with the phrase “finicky filtering”, which is how I’ve been calling this type of use cases for a while now and won’t miss an opportunity to tell people about it.
c) While not necessarily optimal for most scenarios – including this one – I liked Dave’s original idea because of the line of thinking that preceded it.
Namely, he broke up the problem into smaller pieces, did some research to confirm those should be doable - and only then got stuck on the implementation.
If he managed to go any further, I’d have asked him for the lottery numbers because no one is so lucky to guess their way through even the most user-friendly syntax at the beginning of their coding journey. And JavaScript, while one of the most acccessible high-level languages ever made, also has a record number of “gotchas” for both newbies and veterans alike. You’re destined for great coding undertakings Dave, don’t give it up now because it will only get easier from here, exponentially so, especially so with JavaScript.
Overall, d) I wanted to see if I can condense the original idea into as few statements as possible because I felt the discussion was starting to get derailed, kind of missing the forest for the trees.
I do agree with pretty much everything Justin said so far, that interlinking pattern is as close to a universal recommendation as you can get when it comes to finnicky filtering with Airtable.
So yeah, anyone is free to use this script however they’d like, but please keep in mind this is far from how your code should look like if the task at hand is even an ounce more complex and you aren’t way inside your comfort zone.
But on that note, if you’re having trouble with figuring out how this works or can’t get it to work for you at all, just ping me and I can walk you through it. The base,table,and field names I’ve used are all Airtable’s default values when you create a new table and start from scratch, then add an Autonumber and Checkbox fields to it.
P.S. Say finnicky filtering out loud and tell me it doesn’t just roll off the tongue.