("selectedSourceRow is null") after table.selectRow()

Hello,

My team and I have found a possible bug. Our use case is as follows. We are opening a page with url params. This parameter will then be used to find the row of a specific table, select it and after selecting we run a jsQuery that will validate certain fields of the SelectedRow to then open a modal. The problem/bug at the moment is that after selecting the row, when I try to run the jsQuery and access SelectedRow it tells me that it is null. Has anyone experienced this?


2 Likes

Hi Almopt,

In line 1, is the url variable something you defined? I don't think there is anything built in that would be defined there. If you want to get current search params you could do something with urlparams built in info

1 Like

Here's in more detail

const url = new URL(urlparams.href);
const params1 = new URLSearchParams(url.search);
for (const [key, value] of params1) {
  console.log({key, value})
}
1 Like

Also this is a great case where the build in "ask ai" button can do it. I asked it to "log out all the search params of url"
And it wrote this for me:

function logSearchParams() {
  const searchParams = new URLSearchParams(urlparams.href.split('?')[1]);
  console.log(Object.fromEntries(searchParams.entries()));
  return Object.fromEntries(searchParams.entries());
}
1 Like

Hi @julius_jet , thanks for the quick reply.

No, I haven't defined url variable, it's a built in retool variable you can use to access url object. The issue is not getting the data that's coming from the url, but in the selectedRow that even when i select it via selectRow() method it says that is null.

@MiguelOrtiz Any tips on this? sorry for tagging you like this :smiley:

1 Like

Hey @Almopt,

no problem, happy to try and troubleshoot!

A couple of questions:

  • So, is the issue in the second js query or in the first one?
  • Is the selectRow() function in the first query working properly? i.e. is it actually selecting the row you're targetting?

Hi @MiguelOrtiz, thanks for the quick reply!

The issue is in the second query where I am trying to access the the selectedRow.

Yes it's working, the row get selected.

1 Like

What if you first define a constable in your second query with the selectedRow data?

Although that shouldn't be the issue, you should be able to fetch the selectedRow directly without defining a constable..... it is weird you're getting null. What happens when you hover over selectedRow?

In fact, i tried myself and managed to do it:

There could be a race condition, what if you try to debounce your success event handler in your first query to give time for the table row to be selected properly?

1 Like

You're right! I've just added debounce on both query's and it's working. But isn't weird that i need to use debounce when I'm running this query's on success event handler?

1 Like

It is very weird, and I've had many headaches with this (see this post as example)

Strangely, the event handlers and the manual onSuccess/onFailure do not seem to work in the same way.

I've made a habit of testing any succession of queries to make sure that all data is being rendered properly, and if not use debounce or pass the values as additionalScope

What do you mean by saying that event handlers and manual onSuccess/onFailure do not seem to work in the same way? Aren't they the same?

1 Like

They are the same. But I've seen occasions where using a script, e.g.

query1.trigger (onSuccess { query2.trigger() }

where query1 will prepare raw data for an api call which I will reference in query2.

With the above code, query 2 was throwing me errors (and I noticed that the data was not being read correctly from query1), so I decided instead to add an event handler to query1 on success, to trigger query2. This, although the same thing, worked.

1 Like

Oh i see, which means we can't trust manual onSuccess/onFailure :smiley:
Once again, thank you for you help solving this "bug".

2 Likes