Conditional Server Connect Queries

I have a page that has about 30 queries on it. But on page load I really only need to load 4 or 5 of them depending on a URL Parameter value.

For example if URL Parameter = 1 then I only need three of the queries to run. If URL Parameter = 3 I need a different set of server connect queries to run.

Is there a way to only run queries based on a URL parameter? I don’t need to run all 30 queries on page load.

Something like this might do it:
<dmx-serverconnect id="serverconnect1" dmx-bind:url="query.load==1?'dmxConnect/api/myFolder/myAPI.php':''"></dmx-serverconnect>

You can also do it this way round:
dmx-bind:noload=(condition) ? 'noload' : ' '

Thanks Tom, I will explore that!

Would it also work if I have a structure like:

<section id="1"  dmx-show="(query.programid == 1)">
 <serverconnect> ..... </serverconnect>
 <serverconnect> ..... </serverconnect>
 <serverconnect> ..... </serverconnect>
<section id="2"  dmx-show="(query.programid == 2)">
 <serverconnect> ..... </serverconnect>
 <serverconnect> ..... </serverconnect>
 <serverconnect> ..... </serverconnect>

If I hide ‘sections’ does it prevent anything within it from running?

No, that wouldn’t work.

You can nest ternary operators - that might do what you want. With a lot of conditions, it might get cumbersome and difficult to work with. I would probably work on the expression in a text editor and format it while working on it. Nested ternary operators result in pretty horrible code.

There might be a better way to achieve what you want.

So you are suggesting I take all of my server connect queries, example:

<dmx-serverconnect id="totaladditionalliving" url="/dmxConnect/api/programs/programprofile/yes/totals/additionalliving.php" dmx-param:client="query.clientid" dmx-param:instance="query.insttanceid"></dmx-serverconnect>

And go into the code to edit to be more like:

<dmx-serverconnect id="totaladditionalliving" dmx-bind:url="query.programid==1?'/dmxConnect/api/programs/programprofile/yes/totals/additionalliving.php':''" dmx-param:client="query.clientid" dmx-param:instance="query.insttanceid"></dmx-serverconnect>

That looks strange to me … ?

Is there a way to do this in the UI?

Using a conditional region would stop these from running wouldn’t it? Show/hide won’t as it’s just css.

I’m not sure if using conditionals would be the right thing to do or right way to achieve what is wanted here but might work to get things started?

Some other ideas you could explore @brad -setting the SC’s to not auto-load and then using Flows to fire the ones you need based on url params. You could prob use variables, too and onChange dynamic event run certain SC’s.

There will be a correct way to do this but again these might work.

You should use conditional regions and not just show/hide.

The difference is that conditional regions (dmx:if) never render at all if the condition is not met. Also their children like nested server connects are never rendered and execute.

While regular show/hide (dmx-show/dmx-hide) just toggles the css visibility but the contents is still rendered and executed.

So when you have large regions that you don’t want to render always use conditional region. It will be also much faster in performance.

1 Like

A more efficient solution in my opinion:

  1. Keep all server connects as noload.
  2. Create a flow which auto runs.
  3. Inside the flow, use condition to identify the query param value, and add a run step which would load all required SCs.
  4. In case the flow does not capture the query param value correctly, add a wait as the first step. This could happen due to timing issue where param does not have the value yet, and flow has executed before that.

Another option, in case you have at least one SC that load every time.

  1. Keep all server connects as noload.
  2. On success of this SC, use ternary operator to identify param value and load relevant SCs.
1 Like

Conditional regions seems so obvious. Didn’t even think about that. Will try that today.


So, this is what I have but the server connect actions are not executed:

<section id="keysabrecords" is="dmx-if" dmx-bind:condition="(query.programid == 10)">

Update: Checking the dev console it does appear that the proper actions are being executed. But they are returning no data? Why would they not return data?

I am updating this to be a bug. I don’t see any reason it should not return data. Removing the conditional regions loads the data as it should.

I’m not sure is this would affect your situation but adding things into the condition change the path or the bind to conditon1.serverconnect etc

The actions are executing properly (getting 200 status in console) just not returning any data. Remove the conditional region and the data returns as it should.

but have you tried re selecting the data with the new dynamic path I just tried this myself and it works perfectly, if you have a a server connect that you just move to a conditional region the data is still returned but not displayed if you then update the data path what your displaying it works.

I didn’t move any server connects. They were already in sections. I just added the condition to it. So I’m not sure which path would change and why?

{{[0].pages_roles_list_id}} {{[0].pages_roles_list_id}}

Was in the same section after I made it a conditional section the path got edited

maybe just just rebind a piece of data into a new paragraph or some way to test the bind?

Thanks @sid, @mgaussie and @Sorry_Duh and of course @George

This was a bit more work than using conditional regions but it worked like a charm! Now it only loads the actions I need and the page and data load lightning quick.

Results achieved! I always forget about flows. They are powerful. Thank you again!

Leaving this as a bug though as Conditional Regions should have worked.