Apr 08, 2020 04:00 AM
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
).
Can someone help me with that?
Thanks!
Solved! Go to Solution.
Apr 08, 2020 04:19 AM
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
andfieldId
, not thetableId
(infield.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);
Apr 08, 2020 04:19 AM
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
andfieldId
, not thetableId
(infield.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);
Apr 08, 2020 06:03 AM
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!
Apr 08, 2020 06:14 AM
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.