Feb 04, 2022 11:52 AM
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.
Why is my getCellValueAsString(“Nation of Birth”) not returning Germany?
Reagrds
Neil
Solved! Go to Solution.
Feb 04, 2022 12:25 PM
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")
Feb 04, 2022 12:25 PM
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")