How do you pass a Javascript variable value into Application variable?

How do you pass a Javascript variable value into Application variable?

How do you pass a Javascript variable value into Application variable?
Hi Robert,

A Javascript variable is a client side variable that is being stored in the client browser, while an Application variable is a server side variable that is avaiable in the scope of an OutSystems action on the server when the web request is being process. The way to pass a variable on the client to the server, is to make sure that you put it in an input in the form that will be submitted to the server.

For example, to have a Javascript variable string NameJS on your screen passed to the OutSystems local WebScreen variable text NameOS, you must do the following:
  1. Create a hidden Input in your screen (it can be a text box) and give it a name (eg. NameInput);
  2. Bind the OutSystems local variable NameOS to the NameInput;
  3. Make sure that your Javascript logic writes the value of the NameJS Javascript variable to the NameInput (remember that you have the OutSystems runtime property NameInput.Id in your input that gives you the DOM Id of the OutSystems input in runtime so that you can use it in your Javascript logic);
  4. Once the form is submitted to the server (with a button or link), you will have available the NameInput value available in the NameOS local variable. As your javascript logic is writing the NameJS value to the NameInput, this means you will have have achieved your goal - the NameOS variable is holding the value of the NameJS variable.
Kind Regards,

Daniel Lourenço
sorry to dig this one up but, is there a way to do it without a submit button? In the preparation action, for example.
I tried to assign the javascript variable to some input, but after that without the button i cant seem to assign it to a specific session variable.

Thank you
Hi. I have a question about this question , please help me, thanks a lot.
     I have an input widget named "test", and finished bind to a local variable, now I need to get this input widgets value.  
    If I use the Extended Properties of the input widget to set: Properties = ondblclick , Value = "alert(", it works.
    but now I need to get this widget id in a web screen in my javascript code. So how can I get this value?

Thanks & regards! 

When you say "it works", can you describe what happens? I have entered the Extended Property as you said, and I get a message box saying 'undefined'.
To display the value of the input widget, just set the Extended Property value to  "alert(" + test.Id +".value)".

Yes , I just want to know how to reference the widget in the javascript , like your example . I've got it , thanks !
Jie -

I would suggest that you look at many of the Forge components... like the CKEditor component... for examples on how this is done.


I am trying this way to assign javascript variable to outsystems variable, but I encountering problem.
I am running this javascript:

"var r = confirm(""Text"");
if (r == true) {
    " + Input.Id + ".value = 1;
} else {
    " + Input.Id + ".value = 0;
When running it for the first time and clicking OK, I am getting blank value, when I am clicking second time Cancel, I am getting true, and this is previous value. What I shoud do that value won't be previous?
I had tried ajax refresh after RunJavaScript action, but then always getting blank value.
Hi Audrius,

I just copy pasted your Javascript code to the onblur extended property of my OutSystems input, and I get the correct behavior:
- whenever I move the focus away from the input, I get the popup with OK/Cancel;
- if I click OK the input value is set to 1;
- if I click Cancel the input value is set to 0.

It seems that you have the correct JavaScript code, but maybe you are using it in the wrong place?

Completing my previous post...
Just like any other action, RunJavaScript runs on the server side, after the request is submitted from the browser.
The RunJavaScript action injects JavaScript on the response, and the browser will execute and render this response.
The OutSystems variables are assigned when the request is submitted, so long before the response is returned to the browser.
In other words, when the OutSystems variable is assigned, the JavaScript code of the "RunJavaScript" action was not executed yet, so the OutSystems variable is "outdated".


I'm trying to use this logic to get a random number to be passed into a web service and the page be refreshed by Javascript. I can do it through Ajax refresh but the Javascript bit is tricky.

I am able to output the random numbers into text boxes by Javascript, however I am only able to show them not manipulate them.

I've tried passing the typed value into a function (which simply doubles it).

My random number is put into a text input box by this javascript.

I imagine I am doing something really daft, as this article did make a lot of sense, and helped me get started. However, I have reached a bit of a roadblock. Any ideas?

SyntaxEditor Code Snippet

        document.getElementById("RichWidgets_wt3_block_wtMainContent_wtLatestRandomNumber").value = answer;

I have this in my onclick of a navigate button (which goes to "#") for the External URL

SyntaxEditor Code Snippet

"document.getElementById('" + Average1.Id + "').value = '"+DoubleMe("document.getElementById('"+LatestRandomNumber.Id+"').value")+"';"

Hi Everyone,

Can someone point me to a post wherein the Local Variable of a Web Screen can be used in a Javascript (with sample code).

Thank you and regards,


SyntaxEditor Code Snippet

function addTwoJavascriptfields(id1, id2, id3, id4)

    var fieldOne = document.getElementById(id1).value; //gets from Input
    var fieldTwo = document.getElementById(id2).value; //gets from Input
    var sum = parseInt(fieldOne) + parseInt(fieldTwo);
    document.getElementById(id3).value = sum; //places in an Input box
    document.getElementById(id4).innerHTML=sum; //places in an expression