Handling of data outside a conditional

Is it possible to handle data that is set within a conditional statement…

For example, we may perform a different query on a database depending on the data passed to the api, however the processing we do after the query should be common. Currently I’ve not found a way to make data from a query performed inside a conditional statement to be in scope outside of the condition.

So, we want to do something along the following lines…

if condition
then
   response = perform query A
else
   response = perform query A
end

process response

At the moment we’re having to perform the response processing twice as I’ve not found a way to make the data in scope outside of the conditional statement.

I see that the setValue action has a global option - what is that for? It seemed it might be the answer to this, but setting this doesn’t appear to help.

Thanks.

I presume you mean doing condition in server connect action.

Well it is exactly as you said - add a conditional step and under the “then” do the one query and under “else” the other.

Just make sure the names of the queries are the same. And enable the output option.

Also note that the query builder has a lot of conditions inside that allows you to make your query really flexible, so maybe you don’t need a global condition step but just a more flexible query.

1 Like

Yes - sorry, I should have been clearer there.

If I enable the output, then my users will see the query output - is there any way to prevent this as there is sensitive data that we don’t want to send to the user?

Well, if you want to use the query results on your page then you need to have the output enabled. If you just want to use the query results in the server action then you don’t need to enable it.

Ok, maybe I misunderstood what @George meant. I was specifically asking about using the query results outside a condition, and @George stated that I should “enable the output option”. I interpretted that this is required to make this in scope outside of the condition.

I do not want the query exposed to the user, so I don’t want to enable the output option. However if I need to enable the output option to make the query visible outside of the conditional scope, then this is not an option.

Can you clarify this? Do I need to enable output for the query to be visible outside of the conditional scope?

Thanks.

No, you don’t need to enable output in order to access the results of a database query from outside the condition.

1 Like