How to fire a server connect that is within a repeat group?

HI all,

I have a repeat with say 15 rows. Within each row is a server connect API.

I’d like to fire the server connect api within each repeat group and assign the uniqu_id of that repeat.

I’ve tried what I thought would work, and simply on:click and choose run on that SC - but nothing happens?!

Any ideas?

try:

dmx-on:click="serverconnect.load({fieldname: uniqu_id},true)"

Note. Within the repeat (and not child to any conditional element) you can refer to the SC that is within that repeat directly. (not somesection.repeat2.serverconnect.load() )

Thanks @bpj - unfortunately this is what I've tried and it doesn't fire, or even push an error to console.

I'm fine working with the SC within the repeat - I'm trying to activate all 15 at once with a button click that doesn't exist within the repeat itself.

Ah… I get you.
Could you have just one SC outside of the repeat that takes an array of the uniqu_id values when the button is clicked?

1 Like

Yep, I have that one, too :slight_smile:

That's what I'm currently working with, the problem is, the way the system is setup is that I have to do an external API call to our ElasticSearch instance after I have used that - so the whole page of results jumps/refreshes. When using a single SC within a repeat, the data refreshes and not the entire list.

So, I have a working solution (as per your suggestion) - just trying to improve UX a bit and also reduce resource load!

It's a bit strange I can't even fire the SC. I've tried different paths incase the path being generated by Wappler is incorrect which does sometimes happen, e.g.

dmx-on:click="repeatgroup.serverconnect.load({fieldname: uniqu_id},true)

Alas, no luck. I feel as though this is possible and I'm just missing something!

Have you explored from the browser console the dmx.app.data object?

1 Like

Getting somewhere, thank you!

I’m now able to get the SC firing, thank you @JonL - it was indeed as suspected an incorrect path.

The issue I am having now (although very happy to be a step closer) is that the path now accounts for the SC being in the repeat array, and so looks like this:

content.repeat_search_results.items[0].revealContact_repeat.load({external_id: repeat_search_results.id})

‘content’ is the nodejs templating part that I missed.

I’m not sure how to overcome the .items[0] part, as I need this to work for any of the repeat rows chosen, so it could be row item 4 or 15.

I’m also not picking up the actual .id but I’m sure that’s just due to the .item[0] challenge.

I’ve tried aimlessly including $key and $index within the again to no luck…

I’ve struggled with this in the past, so appreciate any advice to solve it now - and for the future!

How is the ID part configured?

There should be a regular ID and a dynamic ID.
On click of the item inside repeat, you need to specify the regular ID for .load().

So what happens here is browser with the dynamic id does not give any warnings of ID being same… But dmx internally knows when regular ID is given, it will find the nearest item with that ID.

Just to revert back slightly to what you’re trying to solve, is it the reload ‘flicker’ in a table as items update? Have you tried adding the unique key property to the table repeat?

When I use the SC in a singular fashion from a button within the repeat, I use and have to use the external_id as this matches against an external api’s unique id. This works fine singularly.

The syntax you see, actually works fine (now) but only on the first item in the repeat due to the item[0] - I’m looking but I’m not sure how to work around that?

You should be able to use $index for that.

Thanks @bpj, I do have the key setup:

Screen Shot 2021-03-19 at 6.41.51 pm

It would be exceptional to avoid the flicker/reload as you say - but as I am calling an external API for the data - is that possible?

Thanks JonL. That's what I thought, so I guess I am using the wrong syntax.

I've tried .items[$index]. with no luck, does this look like the correct syntax to overcome this?

There should be no use of indexes as each row has a separate server connect… and that is the one you need to call from, say a button, inside each row.

In case I am understanding this completely wrong, please ignore.

Thanks Sid, yes I have the above working perfectly. What I’m trying to do is run all of the server connects, from a button outside of the repeat.

You are going to need to perform more dmx.app.data digging :slight_smile:

All the values and paths you need are there. You just need figure out by exploring the object and checking parent/child relationships.

Then you need to loop and run. Have you tried with a flow?

1 Like

Its a quick solution if you are willing to go down the JS magic part.

Ok, thank you JonL, I'll keep digging. I just really get stuck on the array, I can get the first SC working, from the button click - but I can't get it to action any of the remaining 14 due to the .item[0].

I'll keep looking - thank you for your help thus far - you absolutely helped me get further!

Exactly. Looping is the key.