Problem reading <table1.recordUpdates> when running JS query

Hi everyone,

I'm stuck with a problem when trying to run a query which reads the values on a table. It's a 6x6 table in which there are mapped values in all cells. I'm using the values within the cells on a JS query which is supposed to perform a simple calculation using those values, however every time I try running the query, it's crashing with the following message:

message:"Cannot read properties of undefined (reading 'Mes 1')"

It only works after I fill all cells within the column 'Mes 1', but if I clear the table the error starts to happen again.

Here is an excerpt of the script:

for (let i in table1.recordUpdates) {
    if (table1.recordUpdates[i]['Mes 1'] != undefined && table1.recordUpdates[i]['Mes 1'] != "" && table1.recordUpdates[i]['Mes 1'] != null) {
      mes1++
    }
  }

I made sure to initialize the object, so in theory it makes no sense to have this error message, since the object is not undefined. Though one thing that's strange is that when I run a console.log(table1.recordUpdates) it first returns the value undefined and then it depicts the object with all the mapped values, as you can see on the image attached. Does anyone know why this is happening? Thank you so much for the patience and support!

image

Hey @Marcio!

Is this the only place 'Mes 1' is referenced? Would you mind sharing more just in case there might be another reference floating about, or a separate query/component being referenced that might be throwing the error?

I'm curious to know what gets logged if, in the same place in the script, you run something like:

for (let i in table1.recordUpdates) {
   console.log(table1.recordUpdates[i];
}

To your question about the weird log, it looks to be because the value of the console.log expression is undefined. For instance, if you were to write let x = console.log(table1.recordUpdates) and then check the value of x you would see it was undefined. So when you enter it into the console it logs two things:

  1. The value of the expression
  2. The thing you're trying to log itself

You can see similar behavior in your browser console:

Thank you so much @Kabirdas for your response! Now answering your question:

Yes that was the only query where 'Mes 1' was being referenced.

Eventually I bypassed that error by using the following approach:

if (table1.recordUpdates[i] == undefined) continue

After patching the code with the aforementioned conditional, it began to output the values properly.

Once again, thank you for your time and contribution!