Can't change a multi-select

I’ve got a script that I wrote with the scripting block prototype, and it worked perfectly well under that version. Under the new beta, I had to make a few minor tweaks due to API changes, and all appears to be fine except for one part that is being marked as a problem, when it worked just fine previously.

I’m setting a value in a multi-select field using data I’ve extracted elsewhere. The code for the relevant portion that changes the multi-select is pretty bare-bones:

reqtable.updateRecordAsync(reqrecord[0], {"Use": [{name: notes}]});

What’s being highlighted as an error is:

{name: notes}

The notes variable is a string, and should be one of the five options for the multi-select. Like I said above, this part has always worked in the older block, but in the new one the error popup gives me this:

Type '{ name: string; }' is not assignable to type '{ name: "Silent Auction" | "Live Auction" | "Raffle" | "Other" | "Auction"; }'.

If I replace notes in the code with a literal string, it’s not marked as a problem, but when it’s a string variable, it is. I’m lost.

but does it run successfully? I think that is just an issue with the typescript not knowing how to handle it. When you hover over it, the popup will have an option for ‘Quick Fix’ that adds // @ts-ignore to remove the warning.

I added the quick fix, but running the script spits out a massive error message, beginning with:

Error: Error: <root>.records.0.0.id must be an objectId

That leads me to think that something else is amiss. I’ll do a more thorough troubleshooting pass later and report back with any relevant info.

Hi @Justin_Barrett - not sure if this helps you, but this works for me:

let table = base.getTable("Table 1");

let queryResult = await table.selectRecordsAsync();

for (let record of queryResult.records) {
    let value = record.getCellValue("Value");
    await table.updateRecordAsync(record, {
        "Multi-select": [{name: value}]
    })    
} 

In my example, I’m trying to update the multi-select with the value in the Value field:

I get an error in the code editor on {name:value} but the code still runs and works.

JB

1 Like

Thanks. It helps at least to know that the flagging of that code isn’t an isolated case. I’ll ignore it and look elsewhere for the cause of the error message.

Found the source of the error. In the prototype version of the block, the Table.createRecordAsync method returned an array, but this was switched to return a string in the beta. Once I corrected how I was processing the returned data, everything worked.