Skip to main content
Answer

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

  • December 3, 2020
  • 10 replies
  • 81 views

Forum|alt.badge.img+3

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

Best answer by kuovonne

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")},

10 replies

Forum|alt.badge.img+19
  • Inspiring
  • December 3, 2020

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.


Forum|alt.badge.img+3
  • Author
  • Participating Frequently
  • December 3, 2020

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


Forum|alt.badge.img+19
  • Inspiring
  • December 3, 2020

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?


Forum|alt.badge.img+3
  • Author
  • Participating Frequently
  • December 3, 2020

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.


Forum|alt.badge.img+19
  • Inspiring
  • December 3, 2020

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. :winking_face:

Something else in your code is at issue.


Forum|alt.badge.img+3
  • Author
  • Participating Frequently
  • December 3, 2020

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


Forum|alt.badge.img+19
  • Inspiring
  • December 3, 2020

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


Yes, never do that. :winking_face:

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.


Forum|alt.badge.img+3
  • Author
  • Participating Frequently
  • December 3, 2020

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


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • Answer
  • December 4, 2020

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")},

Forum|alt.badge.img+3
  • Author
  • Participating Frequently
  • December 4, 2020

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")},

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