Can't create records: Could not find a choice with that ID or name

Hello,
I use this script for move record from table 1 to table 2, All data is moved except data of type dropdown list (Ville). I show this error: Can’t create records: invalid cell value for field ‘Ville’.
Could not find a choice with that ID or name

let table1 = base.getTable("DATA");
let table2 = base.getTable("Con");
let result = await table1.selectRecordsAsync();
for (let record of result.records) {
    if (record.getCellValue("Prét")) {
        await table2.createRecordsAsync([
            {
                fields: {
                    'ID': record.getCellValue("ID"),
                    'Source': record.getCellValue("Source"),
                    'Agent': record.getCellValue("Agent"),
                    'Nom complet': record.getCellValue("Nom complet"),
                    'Téléphone': record.getCellValue("Téléphone"),
                    'Ville': record.getCellValue("Ville"),
                    'Prét': record.getCellValue("Prét")
                },
            }
        ]);
        await table1.deleteRecordAsync(record.id);        
    }
}
[details="Summary"]
This text will be hidden
1 Like

Yep - that’s expected when you try to create a value in an option list field where such option has not been defined as an acceptable value.

Can you give me an alternative solution

Before we go down that path, have you verified that my hunch is correct by adding the options to the target table and running the code?

Yes, I added the options to the target table, But the same error appears.

Then we haven’t assessed the cause, and therefore there is no point to recommending an alternative approach. :wink:

Something else in your code is at issue.

Is there another solution to moving the records from table 1 to another table?
And thanks in advance :blush:

Yes, never do that. :wink:

Seriously, I am not the guy to ask about making copies of data because I believe it is generally a very bad idea. There are exceptions to this general philosophy that I have but they are very exceptional cases.

The more effective way to create different views of data is to perform logical extensions of the same data - ergo, nothing needs to be replicated; it only needs to be reshaped to fit specific needs. Airtable provides Views for this.

1 Like

Thank you very much for your time, I think this will help me. :heart:

1 Like

The read format and the write formats for single-select values are not the same. Plus, since they re in different tables, the choices will have different ids, even if they have the same name.

Try this.

'Ville': {name: record.getCellValueAsString("Ville")},
4 Likes

It worked :white_check_mark:
Thank you so much :heart:

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.