Server action executing twice

Hi All,

In my application, I have an server action that is executing twice ..

first it executes when the server action is called. later after reaching end of server action  it executes again, wherein it  is suppose to end the action and go back to the UI flow. 

Hi Ankita,


Can you share more information, perhaps you can share a screenshot of your link / button calling the server action?

Are you using a "submit" method where a Ajax refresh would be enough?


Cheers,

João Marques

Is that server action (also) being called in your preparation?

Tim Timperman wrote:

Is that server action (also) being called in your preparation?

 Hi Tim, No it is not called in preparation at all.

 

João Marques wrote:

Hi Ankita,


Can you share more information, perhaps you can share a screenshot of your link / button calling the server action?

Are you using a "submit" method where a Ajax refresh would be enough?


Cheers,

João Marques

 Hi Joao,

Actually this is an "on change" action.

 

So it's most likely the "onChange" that's triggering twice, where you expect it to only trigger once?

You're not changing the value of the input field that has the onChange in the onChange itself?

How do you notice the server action is being called twice? Through debugging? If so, you're debugging in the public area? No other user is by accident also testing the same screen?

Sorry for all the questions, just trying to exclude some scenario's.

Tim Timperman wrote:

So it's most likely the "onChange" that's triggering twice, where you expect it to only trigger once?

You're not changing the value of the input field that has the onChange in the onChange itself?

How do you notice the server action is being called twice? Through debugging? If so, you're debugging in the public area? No other user is by accident also testing the same screen?

Sorry for all the questions, just trying to exclude some scenario's.

 

 Hi Tim,

1) I have an input area, where if the length of text is >3 I want onchange to be triggered. 

2)Within in the action it calls autocomplete complete action. which auto changes the text.

3) I debugged it in public area but no other user is testing it. 

Hi Ankita,


Take into account that whenever you type in a character on the input binded to the OnChange, the OnChange would be triggered and the OnChange takes by default 0.7sec if I'm not mistaken to trigger.


That means that when you type two letters very quickly, the OnChange will run twice, one for the first letter, one for the second.


What is your use case? Because depending on what it is perhaps the OnChange to start with might not be the best approach to avoid that action to run a lot of times (in the case it does heavy queries for instance).


Best regards,

João Marques



João Marques wrote:

Hi Ankita,


Take into account that whenever you type in a character on the input binded to the OnChange, the OnChange would be triggered and the OnChange takes by default 0.7sec if I'm not mistaken to trigger.


That means that when you type two letters very quickly, the OnChange will run twice, one for the first letter, one for the second.


What is your use case? Because depending on what it is perhaps the OnChange to start with might not be the best approach to avoid that action to run a lot of times (in the case it does heavy queries for instance).


Best regards,

João Marques



 Hi Joao,

Do you mean to say that, If I type 5letters quickly, onchange will run 5times?

I have used on change many times but have never encountered this issue. 

So what is the solution according to you?

 

Ankita Kulkarni wrote:

João Marques wrote:

Hi Ankita,


Take into account that whenever you type in a character on the input binded to the OnChange, the OnChange would be triggered and the OnChange takes by default 0.7sec if I'm not mistaken to trigger.


That means that when you type two letters very quickly, the OnChange will run twice, one for the first letter, one for the second.


What is your use case? Because depending on what it is perhaps the OnChange to start with might not be the best approach to avoid that action to run a lot of times (in the case it does heavy queries for instance).


Best regards,

João Marques



 Hi Joao,

Do you mean to say that, If I type 5letters quickly, onchange will run 5times?

I have used on change many times but have never encountered this issue. 

So what is the solution according to you?

 

 

 Ankita, 


You can try tweaking the osOnChangeTimerDelay. 


Refer to this post :  https://www.outsystems.com/forums/discussion/9324/input-on-change-is-too-fast/ 


Cheers,

Tushar

Hi Ankita,


It depends on the use case.

What do you do on the OnChange?

If you're saving the value on the database, perhaps it is best to save on a save / next button, for instance.


Cheers,

João Marques

João Marques wrote:

Hi Ankita,


It depends on the use case.

What do you do on the OnChange?

If you're saving the value on the database, perhaps it is best to save on a save / next button, for instance.


Cheers,

João Marques

 No, Basically we are doing string matching.

 


Try changing the trigger delay of an "On Change", by setting the osOnChangeTimerDelay javascript variable.


The default is 800 which means that the trigger will be invoked 800ms once you stop typing. 


Try changing it to a couple of seconds. Something like osOnChangeTimerDelay = 2000; maybe.


Cheers,

Tushar 

Hi Ankita,


Then the OnChange is the way to go.

You can try and change the delay of the OnChange, running the following javascript on preparation (where the 500 represent 500ms):

"if (osOnChangeTimerDelay) {
  osOnChangeTimerDelay = 500;
}"

Cheers,

João Marques

Tushar Panpaliya wrote:


Try changing the trigger delay of an "On Change", by setting the osOnChangeTimerDelay javascript variable.


The default is 800 which means that the trigger will be invoked 800ms once you stop typing. 


Try changing it to a couple of seconds. Something like osOnChangeTimerDelay = 2000; maybe.


Cheers,


Tushar 

 Hi Tushar,

 I am not so aware of  osOnChangeTimerDelayJS variable. Can you please let me know in details.

Thank you


João Marques wrote:

Hi Ankita,


Then the OnChange is the way to go.

You can try and change the delay of the OnChange, running the following javascript on preparation (where the 500 represent 500ms):

"if (osOnChangeTimerDelay) {
  osOnChangeTimerDelay = 0;
}"

Cheers,

João Marques

 

 Hi Joao,

I have zero knowledge in JS. Can you please explain briefly with these steps?

Hi Ankita,


On your preparation, place the RunJavascript action with the JS code I wrote above (change the 500ms to a value of your choice). You can find this function on the HTTPRequestHandler extension:



When doing this, the AJAX refresh actions (like the OnChange) will have the delay you specified on the value (once again, 500ms in my example).

I believe that's also what the other colleagues were suggesting.


Cheers,

João

João Marques wrote:


Hi Ankita,


On your preparation, place the RunJavascript action with the JS code I wrote above (change the 500ms to a value of your choice). You can find this function on the HTTPRequestHandler extension:



When doing this, the AJAX refresh actions (like the OnChange) will have the delay you specified on the value (once again, 500ms in my example).

I believe that's also what the other colleagues were suggesting.


Cheers,

João


 Hi Joao,

I am aware of this step. LAter this if I add the JS you shared with me I am getting an syntax error. for "{ }"

if (osOnChangeTimerDelay) {

  osOnChangeTimerDelay = 500;


}

 If I just paste this much under script, will that be enough?

Ankita Kulkarni wrote:

João Marques wrote:


Hi Ankita,


On your preparation, place the RunJavascript action with the JS code I wrote above (change the 500ms to a value of your choice). You can find this function on the HTTPRequestHandler extension:



When doing this, the AJAX refresh actions (like the OnChange) will have the delay you specified on the value (once again, 500ms in my example).

I believe that's also what the other colleagues were suggesting.


Cheers,

João


 Hi Joao,

I am aware of this step. LAter this if I add the JS you shared with me I am getting an syntax error. for "{ }"

if (osOnChangeTimerDelay) {

  osOnChangeTimerDelay = 500;


}

 If I just paste this much under script, will that be enough?

 You need to put the code between " " :)

 

João Marques wrote:

Ankita Kulkarni wrote:

João Marques wrote:


Hi Ankita,


On your preparation, place the RunJavascript action with the JS code I wrote above (change the 500ms to a value of your choice). You can find this function on the HTTPRequestHandler extension:



When doing this, the AJAX refresh actions (like the OnChange) will have the delay you specified on the value (once again, 500ms in my example).

I believe that's also what the other colleagues were suggesting.


Cheers,

João


 Hi Joao,

I am aware of this step. LAter this if I add the JS you shared with me I am getting an syntax error. for "{ }"

if (osOnChangeTimerDelay) {

  osOnChangeTimerDelay = 500;


}

 If I just paste this much under script, will that be enough?

 You need to put the code between " " :)

 

 

 Thank you. No more Error. So if I just put this JS action under preparation, it will work right?

Hi Ankita,

Can you please check the usages of the action that you are using inside your onchange.

Or did you bind your onchange action with a button or something.

It would be great if you share snapshot of the usage of your action/ onchange 

Regards,

Vipasha