Javascript variable to a Local Variable not updating the first time

Hi All,


I'am well aware that there are many threads regarding this topic but I cant seem to find a concrete solution. Going back to my issue, Im having a problem assigning a javascript variable value to my Outsystems local variable. I already did what the other thread did and that is to:

  1. Create a local variable that binds to a hidden input
  2. Create a JS variable and use the hidden input Id to assign the JS variable value

The issue in here is that, when I press the Ok button the first time, then the input is updated with the value.

But when I use the local variable in the Server action, it is not updated so my condition is not met.

Please look at my screen:


Here is my server action:


Regards,

Hello amfufutm

When you are executing a SCREEN ACTION (the one you are showing in the image with the Start and End), this code is being executed in the SERVER, not in the client's browser.

This means that any JavaScript code you "execute" here, through the RunJavaScript, you are not executing it immediately,  but is just "preparing" it to be sent back to the Browser with the response from the server AFTER the SCREEN ACTION is executed.

Cheers.

Hi Eduard,


Thank you for that explanation. I suppose i cant use my condition since the var1 value will not be updated at that time. What should be the next step so that my var1 would be updated with the latest value?


Regards,

Hi amfufutm

I think the problem is that you are trying to do thinks backwards.
This strategy, using an input to store a JavaScript value, is used to pass values from the JavaScript being executed in the Browser on a "Client Side" action, when you need this value later on the Server (on a request).

If you want to set the value of an input in the server side, just set the value of the variable associated with the input instead, and when the server sends the response back to the browser, the input will have the value, that can be used by JavaScript running in the browser.

Cheers.