Problem using app variable in query

OS info

  • Operating System : Mac OSX 19.4.0
  • Wappler Version : 2.8.2

Problem description

When updating an app variable value in a dynamic event and using it as input to a query, the query uses the previous variable value, not the updated value.
What am I doing wrong here?

Steps to reproduce

  1. Create a query server action with a GET-variable. Create a Server Connect that uses that server action. Create an App-variable and set it to some value. Create a button with a click dynamic event.
  2. In the button click event set two actions;
    (2.1) Set the value of the variable to a value that differs from the current variable value, ex. set variable.value = variable.value*2.
    (2.2) Add a Server Connect load action and use the variable as input parameter.
  3. Now, when testing this page click the button and the query will be executed. Problem is that it will use the previous value of the variable even though this was changed in step 2.1 above.

See the animation for a better explanation.
I’m new to Wappler and any help or suggestions are most appreciated.

I see the value doubled as displayed in the textbox. Where do you see the old variable value passed? In the serverconnect? Check the network tab in your browser, choose the serverconnect call, see what’s passed as get value

This is what happens during the click dynamic event.

  1. The variable value is being doubled.
  2. The variable is being used as a parameter for the query.
  3. The text area content is set to the variable value.

Step 3 confirms the doubled variable value from step 1.
The browser screenshot below confirms the wrong value being sent as a GET-variable in step 2.
That is my conclusion, but I’m not sure. Maybe I’m missing some fundamental issue here?
I see a lot of new features being dished out every week, but a lot of small known and confirmed bugs not being adressed so this might be a bug, but maybe I’m just doing it wrong?

PS. Maybe this has something to do with duplicate storage of variables or a memory cache problem? Not at all good att debugging java scripts so I’m hoping for some inside knowledge on the inner workings of variable handling and a possible work around…

What are you trying to achieve?
Do you have a link to your page?

I tried testing at my end, when the variable setvalue & serverconnect load are called in the same button click event, it doesn’t seem to work, doesn’t make sense…

I have attached my test file, you can see for btn3 in the below gif, there is something funny happening with the closing bracket of the variable setvalue in wappler.

I have raised similar variable-related bugs in the past (two outstanding at the moment - one & two)… I have always had trouble with variables & had to use many workarounds to overcome the bugs and still use it. The wappler team must focus and get it to perfection, it’s quite fundamental.


test.php.zip (1.2 KB)

Gunnery, this is just a mockup page to illustrate the problem I have with using app variables in queries in a larger project.

The real page is using this method to update a counter value in the db.

If I change the query input parameter to do the calculation itself, ie varDoubledValue*2, the correct value is sent in the GET, but I seems bad practice to have to write duplicate code.

So, why doesn't it work? Could it be a code execution sequence problem?
The first time the "write to db"-button is pressed a "1" is written to the db.
The second time a "2" is written.
The third time a "4" is written and so on...
It seems like the query input parameter is set before the variable gets updated, ie out of sequence.

I thought the code was executed in the same order it was written?
"<button id="btnDoubleValueAndWriteToDB" class="btn btn-primary"
dmx-on:click=
"varDoubledValue.setValue(varDoubledValue.value*2);
sc_insert_with_app_variable.load({testvalue: varDoubledValue.value});
edValue.setValue(varDoubledValue.value)"

Double variable value and write to DB"

1 Like

Akayy, thank you for the comprehensive example!
This makes me sure it’s a bug and I see your two other reports are assigned to Patrick so I guess this will be fixed in the near future (hopefully).

I also have noticed the most right parentheses in expressions disappear sometimes.

You mention you have some workarounds. Would you mind sharing one or two?

@avolo
I am not sure I understand what are you trying to achieve, but when running dynamic actions using the same button (event) - they are executed at once. Event2 does not wait for the Event1 to finish in order to run, they run in parallel.
If you are trying to set a variable and run an action with the new variable value, the action may be running before the new value is set.

If you want to be sure the actions are always executed one after another, either use a flow OR run action2 using the success/updated event of action1.

1 Like

I see Teodor, that explains a lot. I will change this into a flow instead.
Thank you for the clarification.

Woww, that’s a big learning, wish I knew that before! I thought it was sequential