Issue with Transformer when referring to Query

Hey guys,

Thanks in advance for checking this out.

Something very strange is happening. I am able to get my dashboard working perfectly, then I switch to preview and the transformer gives me an error of Could not evaluate transformer in query2: Error: Cannot convert undefined or null to object

This wasn't occurring whilst editing my app, and when I return to edit app the issue persists. I fiddle around with it for a while, it randomly begins working again, and the process repeats.

Query 1: 'SELECT * FROM events LIMIT 5000;' (used in table 1)
Query 2: 'SELECT datapoint FROM events WHERE id={{table1.selectedRow.data.id}}' (used for table 2)

The query itself for table 2 seems to be working, but I also have the following Transformer acting on the table 2 data:

**const array1 = {{query2.dataArray['0'].datapoint['0']}}**
// this is where the error is happening! The error reads 'Cannot read properties of undefined. Reading [0]. 

const table = JSON.stringify(Object.entries(array1).map(el => {
  let var1 = parseInt(el[0])
  let var2 = el[1].name
  let var3 = el[1].object_id
  return {var1, var2, var3}
}))

return JSON.parse(table)

I would think it was a data issue, but if I re-input the same code it starts to work again. This code is fine. Any suggestions as to what people think is going wrong?

P.S. These are not original variable, table names etc

Hello @thelorddoyle I'll find out for you what's going on with your transformer, and why it works sometimes vs. not. Hang tight, thanks!

Hey Alina, I solved it. I ended up making my JS async and that solved it!

1 Like

That's great!