Help

Re: Scripting to delete a value in a single select

Solved
Jump to Solution
758 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Tech_Support2
5 - Automation Enthusiast
5 - Automation Enthusiast

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
Kamille_Parks
16 - Uranus
16 - Uranus

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
Kamille_Parks
16 - Uranus
16 - Uranus

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.)