Jun 26, 2020 06:12 AM
Hello,
I’m facing error : “Record missing in table”. I work on Block and I’m creating a custom block.
I have a table (“my_table”) with data and I want to read all the fields for a specific primaryField. The specific primarityField will be transmitted in a Label Select (value). The code works, but when I delete one line from my table, I got the error : “Record missing in table”. I can add new line without error.
Do you think my error is in the declaration of record ? Did I misunderstand one principal of REACT or similar ? Bellow my code to help to solve the issue :
const base = useBase();
//--------------------------- label Select --------------------------
// We get all the fields from "my_table" and put in selection_value_picker
const table = base.getTableIfExists("my_table");
const selection_value_picker = [];
for (let i = 0; i < table .fields.length; i++) {
selection_value_picker.push({
value : table.fields[i].name,
label : table.fields[i].name
});
}
const [value, setValue] = useState(selection_value_picker[0].value);
//-----------------------END label Select -----------------------------
//---------------------information selected to be rendered ------------------------------
const doneField = table ? table .getFieldIfExists(value) : table.getFieldIfExists(table.primaryField.name);
const records_desc = useRecords(table , {fields: [table.getFieldIfExists(value)]});
const my_item_description = records_desc ? records_desc.map(record => {
const my_item_desc_value = record.getCellValueAsString(doneField)
return(
<div >
<a
onClick={() => {
expandRecord(record);
}}
>
{my_item_desc_value || "NA"}
</a>
</div>
)
}) : null;
Then I call {my_item_description }
to render the information and I use <Select
and onChange() to change value with setValue(). Manipulate the Block independantly will work : I can get the render dependant on the onChange value transmitted. In my table, I can even create a new entry. But when I delete one row , I got the error ‘Record missing in table’ (at the line const records_desc = useRecords(table , {fields: [table.getFieldIfExists(value)]});
Any idea ? Thank you for your help.
Viken
Jul 17, 2020 06:04 PM
I haven’t been able to reproduce the error you’ve described, but I have two ideas about things you could try.
First off, whenever you’re rendering an array of components in React, you should assign a unique key
prop to each component. In your case, the record’s id
is a good candidate for this:
const my_item_description = records_desc ? records_desc.map(record => {
const my_item_desc_value = record.getCellValueAsString(doneField)
return(
- <div >
+ <div key={record.id}>
<a
That change may resolve your issue because it will help React track component identity across rendering operations.
Secondly, the doneField
binding will take on the value undefined
whenever the selected field is removed from the table. That will cause an error in your application (though not exactly the error you’ve reported). To avoid that, you can extend the condition that controls when child components are created:
//---------------------information selected to be rendered ------------------------------
-const my_item_description = records_desc ? records_desc.map(record => {
+const my_item_description = (records_desc && doneField) ? records_desc.map(record => {
const records_desc = useRecords(table , {fields: [table.getFieldIfExists(value)]});
Finally, some tips for posting support requests:
Following that advice will make it more likely that other folks will help out (and more likely that they’ll find a solution).