Help

'Loading' a record

Topic Labels: Extensions
Solved
Jump to Solution
733 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Neil_Thorman
6 - Interface Innovator
6 - Interface Innovator

Is ‘loading’ a record the right concept.
Up to now I’ve been using lines like:

let record = await input.recordAsync("Who is Mum", view);

and in my head this has then let me wokr with a chosen record. But now I want to ‘load’ a record from a ‘link to another record field’ and I suspect I’m missing a fundamental point somewhere:

My code:

let table = base.getTable("Characters")
let deadMen = table.getView("Living Males")
var deadMansRecord = await input.recordAsync("Who Died", deadMen);

let theWiddow = deadMansRecord.getCellValue("Spouse")
let theWiddowID = theWiddow[0].id

console.log(theWiddow)
console.log(theWiddowID)

let widdowHome = theWiddow.getCellValueAsString("Nation of Birth")
console(widdowHome)

and the result when I run it for Albert.

Screenshot 2022-02-04 at 19.50.52

Why is my getCellValueAsString(“Nation of Birth”) not returning Germany?

Reagrds
Neil

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

When retrieving the contents of a linked record field, you don’t have direct access to the linked records. What Airtable returns is an array of objects, with each object only containing the name and ID of the linked record, as your console log shows.

To get the record itself, you’ll need to directly retrieve it from the table where it lives using its ID. In this case, the target record is in the same table, so you won’t need to get a new table instance.

To retrieve a record using its ID, use the selectRecordAsync() method on a table. To extend your example above:

let theWiddow = deadMansRecord.getCellValue("Spouse")
let theWiddowID = theWiddow[0].id

let widowRecord = await table.selectRecordAsync(theWiddowId)

Now you can use the getCellValueAsString method on widowRecord.

let widdowHome = widowRecord.getCellValueAsString("Nation of Birth")

See Solution in Thread

1 Reply 1
Justin_Barrett
18 - Pluto
18 - Pluto

When retrieving the contents of a linked record field, you don’t have direct access to the linked records. What Airtable returns is an array of objects, with each object only containing the name and ID of the linked record, as your console log shows.

To get the record itself, you’ll need to directly retrieve it from the table where it lives using its ID. In this case, the target record is in the same table, so you won’t need to get a new table instance.

To retrieve a record using its ID, use the selectRecordAsync() method on a table. To extend your example above:

let theWiddow = deadMansRecord.getCellValue("Spouse")
let theWiddowID = theWiddow[0].id

let widowRecord = await table.selectRecordAsync(theWiddowId)

Now you can use the getCellValueAsString method on widowRecord.

let widdowHome = widowRecord.getCellValueAsString("Nation of Birth")