Help

Record missing in table - Block

Topic Labels: API
1247 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Viken_Toramania
5 - Automation Enthusiast
5 - Automation Enthusiast

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

1 Reply 1
Mike_Pennisi
7 - App Architect
7 - App Architect

Hi @Viken_Toramanian,

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:

  • Include the complete sample code. If people have to write their own code to observe your problem, then there’s a good chance the code they write will not match yours, and this may interfere with their attempt to help you.
  • Include a precise set of “steps to reproduce.” Instead of describing things that work and things that don’t, explain the exact actions someone should take to see the problem you’re seeing.

Following that advice will make it more likely that other folks will help out (and more likely that they’ll find a solution).