Help

Re: Scripting Error

1376 0
cancel
Showing results for 
Search instead for 
Did you mean: 
chrisberry
6 - Interface Innovator
6 - Interface Innovator

Any Idea why the scripting block would give me this error?  I've seen 
let query = await table.selectRecordsAsync();

used in other scripts.

Screenshot 2023-10-27 at 6.55.29 PM.png

4 Replies 4
Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

Hey @chrisberry ! Can you post a screenshot of more of your code? selectRecordsAsync is working for me. Prob just a small typo somewhere. Here's an example:

Screenshot 2023-10-27 224537.png

// Define the base
const base = ('DMB_Data');

// Define the table name and column names
const table = 'DMB_Products_Groups';
const columnA = 'email';
const columnB = 'full_name';
const columnC = 'multiple_emails';

// Initialize an empty object to store the mapping
const mapping = {};

// Query all records from the table
const query = await table.selectRecordsAsync({fields: table.fields});

// Iterate through the records and build the mapping
for (const record of query.records) {
const valueA = record.getCellValue(columnA);
const valueB = record.getCellValue(columnB);

if (valueA && valueB) {
if (!mapping[valueB]) {
mapping[valueB] = [];
}
mapping[valueB].push(valueA);
}
}

// Update the records in Column C
for (const record of query.records) {
const valueB = record.getCellValue(columnB);

if (valueB) {
const valuesA = mapping[valueB];
record.setCell(columnC, valuesA);
}
}

@chrisberry Can you share more about how you got this script, how it was written, and your scripting skill level?

The reason you are getting the error is because your variable table is not actually a table object. It is a text string matching the name of a table. To get an actual table object, you can use

const table = base.getTable("DMB_Products_Groups").

Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

@chrisberry simple fix, try changing this:

const table = 'DMB_Products_Groups';

to this:

const table = base.getTable('DMB_Products_Groups');

 

Also change this line:

const query = await table.selectRecordsAsync({fields: table.fields});

to

const query = await table.selectRecordsAsync({fields: ["Field Name 1", "Field Name 2"]});

Where "Field Name 1" and "Field Name 2" are the specific names of your fields. (if need more than 2, use commas to separate more entries. 

Let me know if that works for you!