Help

Re: Lookup field options

Solved
Jump to Solution
1653 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ivan_D_halluin
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi!

I wanted to show a lookup field as <RecordCardList />, but I can’t access the original field. I’m only getting the recordId and fieldId, not the tableId (in field.options).

image (67)

Can someone help me with that?

Thanks!

1 Solution

Accepted Solutions
Emma_Yeap
Airtable Employee
Airtable Employee

Hi Ivan,

Not sure I understand your question - are you saying that you have a lookup field (set up with a linked record field and a field in another table), and you want to retrieve the field that is being looked up in the other table?

How does this relate to using RecordCardList, could you elaborate? (You can simply use <RecordCardList records={records} fields={[lookupField]} /> after getting the records in the table with useRecords(table))

I’m only getting the recordId and fieldId , not the tableId (in field.options ).

The screenshotted options you have contain recordLinkFieldId (the MULTIPLE_RECORD_LINKS field the lookup is referencing) and fieldIdInLinkedTable (the field being looked up in the other table, via the linked records) - neither is a recordId. (Tip: You can tell by the 3 letter prefix in the id. fld is a field)

You can find the linked table id in the options of the MULTIPLE_RECORD_LINKS field:

const base = useBase()
const table = ... // the table the lookupField came from
const lookupField = ... // the field you already have
const linkedRecordsField = table.getFieldById(lookupField.options.recordLinkFieldId);
console.log('Linked table ID', linkedRecordsField.options.linkedTableId);
// retrieve the linked table
const linkedTable = base.getTableById(linkedRecordsField.options.linkedTableId);
const originalField = linkedTable.getFieldById(lookupField.options.fieldIdInLinkedTable);

See Solution in Thread

3 Replies 3
Emma_Yeap
Airtable Employee
Airtable Employee

Hi Ivan,

Not sure I understand your question - are you saying that you have a lookup field (set up with a linked record field and a field in another table), and you want to retrieve the field that is being looked up in the other table?

How does this relate to using RecordCardList, could you elaborate? (You can simply use <RecordCardList records={records} fields={[lookupField]} /> after getting the records in the table with useRecords(table))

I’m only getting the recordId and fieldId , not the tableId (in field.options ).

The screenshotted options you have contain recordLinkFieldId (the MULTIPLE_RECORD_LINKS field the lookup is referencing) and fieldIdInLinkedTable (the field being looked up in the other table, via the linked records) - neither is a recordId. (Tip: You can tell by the 3 letter prefix in the id. fld is a field)

You can find the linked table id in the options of the MULTIPLE_RECORD_LINKS field:

const base = useBase()
const table = ... // the table the lookupField came from
const lookupField = ... // the field you already have
const linkedRecordsField = table.getFieldById(lookupField.options.recordLinkFieldId);
console.log('Linked table ID', linkedRecordsField.options.linkedTableId);
// retrieve the linked table
const linkedTable = base.getTableById(linkedRecordsField.options.linkedTableId);
const originalField = linkedTable.getFieldById(lookupField.options.fieldIdInLinkedTable);
Ivan_D_halluin
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Emma,

I will add some context of my need.

When the user select a row on Table A, I want to display more details about the record (I have a view which contains the fields I want to display on my custom block), but one of the field is a Lookup Field of Record, I would prefer to display Record Card instead of just the names.

I didn’t understand the first time why there wasn’t the TableId directly in the lookupField options, but now I see!

Thank you for your help!

Have a nice day!

Ah, I see! Thank you for the context, and no problem!

I’ll check if there’s a reason it’s currently not in the lookup field options.