Help

Re: Check box of first row of the table every x hours

789 1
cancel
Showing results for 
Search instead for 
Did you mean: 
olivier_00
4 - Data Explorer
4 - Data Explorer

Good afternoon,

I m trying to script so that in a specific view of my table, ever 15 minutes, the first row will have box checked.

As checked rows are filtered out, another one will be in first row for the next run.

I managed to script that it check all the boxes at once with this script:

let table = base.getTable(“Table Name”);
let view = table.getView(“View Name”);
let query = await view.selectRecordsAsync({fields: })

let updates = query.records.map(r => {
return {id: r.id, fields: {“Checkbox”: true}}
})

while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}

Thanks!

5 Replies 5

Since you only need to update one record, and you’re already using Views so sorting is taken care of, you can make use of Javascript’s .find() function or simply taking the first item in the array of records.

let table = base.getTable(“Table Name”);
let view = table.getView(“View Name”);
let query = await view.selectRecordsAsync({fields: })

let firstRecord = query.records[0]

await table.updateRecordAsync(firstRecord.id, {"Checkbox": true})

Thank you.

it worked until the last line.
but now when i try to run it again i get this:
SyntaxError: Invalid or unexpected token
on line 1
at s on line 1
at Generator._invoke on line 1
at Generator.next on line 1
at t on line 1
at a on line 1
on line 1
on line 1

let table = base.getTable(“English Videos”);

let view = table.getView(“social media unposted”);

console. log(view)

let query = await view.selectRecordsAsync({Fields:[“Posted”]});

//console. log(query)

let firstRecord = query.records[0];

//console. log(firstRecord)

await table.updateRecordAsync(firstRecord.id, {"Checkbox: true}); ← this wasnt working when the rest was working.

EDIT: commenting out this last line and doing the consolelog first record, everything is fine to this stage. so the last line really is causing the problem.

EDIT 2: just had to replace Checkbox by the name of the field. all working now.

Thank you again

olivier_00
4 - Data Explorer
4 - Data Explorer

I would like this script to run every XX minutes.

Is there a way to make this happens?

To do that you’ll need to run it as a “Run a script” action as part of an automation. That’s only possible if your base is in a Pro-plan workspace or higher. If you fit that criteria, create an automation that uses the “At a scheduled time” trigger, with the options set to the interval that you desire. Add a “Run a script” action to the “Run actions” section, paste your code into it, and you should be good.

Thank you, will have to upgrade then.