Skip to main content

Scripting Error

  • October 27, 2023
  • 4 replies
  • 17 views

Forum|alt.badge.img+10

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

used in other scripts.

4 replies

Arthur_Tutt
Forum|alt.badge.img+19
  • Brainy
  • 119 replies
  • October 28, 2023

Hey @PickThisBerry ! 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:


Forum|alt.badge.img+10
  • Author
  • Inspiring
  • 14 replies
  • October 30, 2023

Hey @PickThisBerry ! 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:


// 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);
}
}

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • October 31, 2023

@PickThisBerry 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
Forum|alt.badge.img+19
  • Brainy
  • 119 replies
  • October 31, 2023

@PickThisBerry 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!