Sucess event handler keeps on triggering

Hi, I have a usecase that update the value of total pages of pageInput component after getting response from rest api.

The issue I am getting here after getting the successfull response from rest api my event handler keeps on triggering until page broke.

Do anyone know what can be the issue and how can I resolve it.

This is my success event handle which just set value of a variable

Hi there @Awais_Tahir,

It could be that your query16.trigger is updating a component that your rest api request is referencing. As such you enter into a loop because your api refreshes your query 16, which refreshes a component, which triggers your api.

Try changing your api request to manual in Run behaviour to see if that's what causing the issue.

3 Likes

Hi @Awais_Tahir ,

This is probably just the case of dependency loop, and it might be good to rethink how the process is working, but without much info, I would say try setting the query run behaviour to manual, or setting the success query to run periodically in the advanced part of the query settings.

1 Like

@MiguelOrtiz @Milan_Kalem Thank you for response, Yes I got it.
query16 actually updates the total pages of pageInput component. and every time when total pages count updated it ran the rest api again and this creates a loop.

I update the value of Page count
Screenshot 2024-06-13 at 2.10.40 PM

I want to update the value of page count on every response of rest api without creating a loop, is there any way to do it except setting the behaviour to manual

Hello @Awais_Tahir!

You can set the component to update on every response of a REST API. The question is, when do you want this to run? On a user input or event?

You can have two queries, one for the initial load to get the page count. Then a second query to a REST API when the page count needs to change, and tie this to the event that should trigger this.

1 Like

@Jack_T Thank you for response.

My REST API return records and total page count. I update the total page count and table records on getting the response from rest api. as soon as I update the Total Pages of pageInput component, it send the request to api again and creates the loop.

I have applied filters on my table, e.g. if I want to see all the records with 30 years of age, I need to apply filter on age, my REST API will fetch the records on the basis of applied filter, and total page count will also changed (based on that filter). I put that total pages value to PageInput component on every filter.

I have tried to do this in a separate query but issue remains same.

It seems to be that you are in an event loop.

Getting data-->update component-->get data-->update component, etc.

You need to break the loop by changing the order of events that are running.

You could have the REST API run only when a filter is applied. Not when the component has data set in it.

As long as the Success of the component update triggers an API call that will trigger the loop to begin again. I would recommend removing the query call on Success and only call the API when the page load/when the user clicks a button to search, clicks a button to filter or changes the page(pagination is another story).

There needs to be an end of the loop where nothing else runs after updating the component :sweat_smile: