Update local variable/client variable via Javascript

Hi all, im current getting trouble with a very simple requirement. Even though there are a lot of thread in forum but non of those solve my problem. Its as below:

. I have a variable named "progress" - which is used in some other places

. An "Interval" made by js, update progress every 0.5s.

I tried to use below solutions:

1) use 1 textbox to store value calculated from js and bind textbox to progress local variable.

2) use 1 textbox to store value calculated from js. Trigger event "change" by js and configure "Onchange" event in OutSystems so that it can update progress local variable.

var myVar = setInterval(myTimer, 500);

function myTimer() {
  var pg = Number(document.querySelector("#progress_input").value);
 
 document.querySelector("#progress_input").value = pg + 1;
    // Create a new 'change' event
    var event = new Event('change');
    // Dispatch it.
    document.querySelector("#progress_input").dispatchEvent(event);
}

in both cases, the textbox value changed, but not progress local variable.

And the fire event code doesnt seems to work properly through.

Env:

ServiceStudio: 11

Mobile/Reactive web.

Many thanks in advance!

Solution

I am not sure whether modifying the textbox value like this should be able to update the progress local variable.

Another approach could be to call a client action from your javascript to update the progress variable.

var myVar = setInterval(myTimer, 500);

function myTimer() {

  $actions.IncrementProgress();
}

And in the IncrementProgress client action set progress = progress + 1.

I hope this helps.

Kind regards,

Stuart

Solution

Hi Stuart,

Never expect it's so simple like that :). Actually, I wanted to use js to access the variable so that i can control when the interval should stop or just calculate something base on that... But that can be solved easily by putting the progress value to a textbox and then use js to read again.

Thank you very much for your help! :)

Best regards,