Help

Re: Script to check a checkbox field based on an adjacent button field being clicked

1404 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Burner
7 - App Architect
7 - App Architect

Hi,

I need help to create a script for a button field such that when I click the button for any record, an adjacent (checkbox) field for that record gets ‘checked’.

Any help would be very appreciated.
Thank you in advance.

6 Replies 6

Could you explain the use case in a bit more detail? Is there a reason why the checkbox field can’t be clicked directly? Is it prevented via user permissions?

Also, where will this button field be used? If it’s in an Interface, it’s not going to work. Buttons in interfaces can’t currently trigger scripts. An alternate approach that’ll work in that environment would be to use a single-select field that triggers an automation, which wouldn’t require a script.

Thanks, Justin. Thanks for clarifying the limitation of the button in an interface. I didn’t realize that.

No matter, my question was still about the a button field int he Grid view. I admit the toggling a checkbox by clicking a button wasn’t the best example, but in general, I meant clicking a button field and being able to set a value of another field(s) for that record, whether it was a checkbox, formula, whatever.

So if I click a button for a record, I’d like the three fields listed below to have their values set as follows:

  • Checkbox = TRUE
  • Timestamp (Formula field) = NOW()
  • Note (Single line text field) = “This is a note for {Record ID}”

Basically, in clicking a button, the values of three other fields for that record get updated. I feel confident that I can tweak the script to what values these columns get updated to, but I don’t even know where to begin with writing such a script.

P.s.
As I think about this more, I realize that I could accomplish this by using a checkbox as a trigger instead of a button. Set the checkbox as the trigger for an automation and when that checkbox is checked, update the values of field 1, field 2, and field 3 – but I’d like to do this with a button

Can you clarify your level of coding experience, your level of interest in learning how to write Airtable scripts, and how much of a start you want to be given?

There are several sample scripts in the documentation. The documentation also has info on how to read and write field values for each field type.

This project is actually a fairly good one for learning how to write scripts for Airtable.

Note that you cannot set the value of a formula field.

Hi @kuovonne ,

I’ve written some Python and C code back in the day and so I’m familiar with basic programming fundamentals and such. Never studied any Javascript, which as I understand, is the language using in Airtable scripts. I do get basic concepts like variables, arrays, etc. just that I’m not familiar with things like Javascript events, async requests, promises, and such. Given some start up code, I suppose I should be able to infer what that code does for the most part, but may need some help to understand what a particular line is doing.

Thank you for sharing the documentation link. I’ll give that a read as well.

As for setting the value of a formula field, I meant setting it as the result of a formula. So for e.g. setting a formula to NOW() and formatted as a date to include time is what I meant.

Thanks for the clarification on that point. It’s important to note, though, that the output of the NOW() function isn’t precise. Per the documentation, that only refreshes roughly once every 15 minutes when a base is open, and about once per hour when it’s closed.

Thankfully a script doesn’t need to rely on a formula field to get the current time. That can be done directly in the script using the Date() object. Get the current date and time—meaning the precise time that the line is executed—like this:

let datetime = new Date();

Then the script can insert that value into a date field as part of updating a record.

Thank you so much. This is great!