JS running inconsistently on page load

We are trying to use a JavaScript function to pull our user data on page load, but it does not seem to be consistently running.

Why do it that way rather than binding the widgets so that the query gets called automatically? We found that our page load times were dramatically improved if our data was first put into appsmith.store and then referenced from there. Since the query isn’t bound, we need to manually call it somehow. The query is as follows:

`loadStudents: async () => {
	ProgressLoading.isVisible = true;
	if (appsmith.store.SearchResults == null)
		await Get_Students.run();
		storeValue('StudentIndex', 0);
		storeValue('SearchResults', Get_Students.data);
	ProgressLoading.isVisible = false;

The function is set to run on page load, and sometimes it does - but usually not.

Hello and welcome to our community!
I’m sorry you are facing trouble with functions running on page load. Are you on cloud or self-hosted?
Could you please share a screen recording to show the issue in action?

Hi Amelia,
We are self-hosted. And of course, the best part about an inconsistent problem is that when I try to take a recording, it works. I am not sure if we changed something that had an unintended side effect, but so far it has worked every time I try to do a capture.

However, one thing that does not work is the Progress Bar. We have a widget “ProgressLoading” that is supposed to be visible while the function is running as it does still take several seconds. It never becomes visible. Are we doing the “.isVisible” property wrong somehow?

Please let us know if you get the issue again and try to capture a screen-recording.
As for the ProgressLoading widget, it won’t work if you try to assign a value to it like this: ProgressLoading.isVisible = true/false because Appsmith is reactive. You’ll need to use storeValue() to achieve this. Please check this documentation that explains how to configure widget properties and let us know if you have any questions or face issues while implementing it.