Yes, All the queries needs to be executed when the dropdown is selected. as i need to display the response object values in the data visualization and the labels. 

When i try the same query in the UI Builder it takes longer 15~20 seconds in the background script it takes 11 seconds

Does the customer need to have precise numbers at the time of the dropdown selected or each time dropdown is selected it can have rough estimate? What Im trying to acheive is to move that logic into scheduled job and result for both array queries will be stored into JSON field somewhere at your table. You can than simply query that one field without computation a display the data. Problem is how often will you need that data to be fresh, because you could slower the instance for all in general

So each time a dropdown option is selected the data resource runs and the query is updated with the dropdown option, For example from the code this line: 

"operational_status!=6^owned_by.u_program=" + usedByOrgVal

 

Here usedByOrgVal will store the dropdown option.


Also when the dropdown option is "All", Which is the initial case when the page load the query will be without the usedByOrgVal value, For example from the code this line:

"operational_status!=6^owned_by.u_program"

 

How can we move the logic into a scheduled job? Can we try doing that approach?

Before moving to that approach please read documentation how scheduled job works if you are not familiar with it. Maybe this functionality is not desired. 

What i would try first is query all of the data immediatelly on page load and store them into state. Then i would use client script to determine what data will be loaded to that components from state. 

You will have one big query at the beggining but then switching between values should be smooth

Please let me know if my understanding is correct.

Step1: Trigger the data resource on page ready and store the object output into the client state parameters using the client script.

Step2: Using the client state parameter value in the data visualization
Below is the snapshot:
Step 1:

Hari1_0-1737199596535.pngHari1_1-1737199631856.png

Client Script:

Hari1_2-1737199702232.png

Calling the client parameter value in the data visualization

Hari1_3-1737199761960.png

It is still taking 18~20 minutes to load using this approach. Please let me know if this the approach that you were explaining.

I believe that the code in the data resource is taking long time due to the data pull through queries passed.