Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Scripting to delete a value in a single select

Topic Labels: Scripting extentions
Solved
Jump to Solution
457 2
cancel
Showing results for 
Search instead for 
Did you mean: 

I have a button/script that I want to be a toggle the value in a single select field. If the value is blank, I want to e button to mark it “Absent”; if the value is “Absent”, I want the button/script to make the cell blank.

In Airtable Scripting, I see how to delete choices, but I don’t think I want to delete the choice, just the value. (I am trying to avoid having a second option of “Present”, as I know my users will assume they have to mark all clear cells as “Present”.)

Here’s my script:

// Select the recordId that houses the button
let tableClassReg = base.getTable("Class Reg");
let record = await input.recordAsync('',tableClassReg).catch()
//console.log(record.id, record.name);

// read in a specific field
let entry = record.getCellValue("D1 Atnd");

// toggle that field
if (entry.name=="Absent") {
    await tableClassReg.updateRecordAsync(record, {
        'D1 Atnd':{"name":""}  //<-- here's the problem
    });
} else {
    await tableClassReg.updateRecordAsync(record, {
        'D1 Atnd':{"name":"Absent"}
    }); 
};

I’ve tried “”, empty square brackets, null. But it doesn’t seem to allow me to force it to clear a value from a cell. Should I be using a different call?

Related: if I give a user a read-only view link, will the button fail to work at all?

1 Solution

Accepted Solutions

Both of the following work for me:

await table.updateRecordAsync(record, {"Single Select": null})
await table.updateRecordAsync(record, {"Single Select": undefined})

Yes.

See Solution in Thread

2 Replies 2

Both of the following work for me:

await table.updateRecordAsync(record, {"Single Select": null})
await table.updateRecordAsync(record, {"Single Select": undefined})

Yes.

Correct on all accounts. Thank you!
(I was really hoping I found a sneaky way around Airtable’s inability to grant limited access.)