Help

Re: selectRecordAsync only returns record ID and Name

Solved
Jump to Solution
2810 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Justin_Yorick
4 - Data Explorer
4 - Data Explorer

I am attempting to create a simple script which will count the number of entries in a linked lookup field. My plan was to invoke .selectRecordAsync() on the table of interest to pull the records and count the number of entries for a given record in that field.

I’ve run into an issue early on with this script: the selectRecordAsync call appears to only be returning the name field and Id for the records, but no other data. My code is below.

let vendorTable=base.getTable("Vendors");
let quoteField=base.getTable("Vendors").getField("Quoted Parts")
let records= await vendorTable.selectRecordsAsync()

console.log(quoteField)
console.log(records)
let exampleValue=records[0].getCellValue(quoteField)
console.log(exampleValue)

I’m getting the following responses in the console.
image
image

image

My table is structured as follows:

image

The only issue I can think of off hand is that all of the fields (aside from name) are linked or lookup values.

What am I missing here?

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

What is returned by calling selectRecordsAsync on a table instance is an instance of another class known as a RecordQueryResult. It’s not a direct array of records that can be accessed as you’re trying to do in this line:

let exampleValue=records[0].getCellValue(quoteField)

A RecordQueryResult instance contains three properties:

  • recordIds - a string array of all record IDs from the table
  • records - an array of Record instances representing all records in the table
  • getRecord - a method that can be used to retrieve a single record by its ID

On a side note, you don’t need to use the getField method on a table to retrieve a field to use as part of a getCellValue call. You can just pass the string name of the field.

Using that info to access the first record from the records array on that query, your code whould look like this:

let vendorTable = base.getTable("Vendors");
let query = await vendorTable.selectRecordsAsync()

let exampleValue = query.records[0].getCellValue("Quoted Parts")
console.log(exampleValue)

See Solution in Thread

2 Replies 2
Justin_Barrett
18 - Pluto
18 - Pluto

What is returned by calling selectRecordsAsync on a table instance is an instance of another class known as a RecordQueryResult. It’s not a direct array of records that can be accessed as you’re trying to do in this line:

let exampleValue=records[0].getCellValue(quoteField)

A RecordQueryResult instance contains three properties:

  • recordIds - a string array of all record IDs from the table
  • records - an array of Record instances representing all records in the table
  • getRecord - a method that can be used to retrieve a single record by its ID

On a side note, you don’t need to use the getField method on a table to retrieve a field to use as part of a getCellValue call. You can just pass the string name of the field.

Using that info to access the first record from the records array on that query, your code whould look like this:

let vendorTable = base.getTable("Vendors");
let query = await vendorTable.selectRecordsAsync()

let exampleValue = query.records[0].getCellValue("Quoted Parts")
console.log(exampleValue)

Thanks @Justin_Barrett . This was exactly the issue. Much appreciated