How to assign javascript value to out-system local variable

How to assign javascript value to out-system local variable

  

Please find the attachment, please help. 

Hi Sachin,

You need to assign the js variable to a text box. The variable linked to that textbox will get the value. You can hide the text box with CSS.

Regards,

Marcelo

Hi sachin,

I agree with Marcelo

Steps you have to do

take one input widget and set its display to false and name it hiddenInput

now link your outsystem variable to this input variable

Now In javascript part your code should be

"var jsvalue='Test';

document.getElementById(' "+hiddenInput.id+" ').value=jsvalue;"





Lovely Priyadarshini wrote:

Hi sachin,

I agree with Marcelo

Steps you have to do

take one input widget and set its display to false and name it hiddenInput

now link your outsystem variable to this input variable

Now In javascript part your code should be

"var jsvalue='Test';

document.getElementById(' "+hiddenInput.id+" ').value=jsvalue;"




Hi Priya,

How to  link outsystem variable to this input variable?


Regards,

Sachin





Solution

Hi Sachin,

In addition to Marcelo Ferreira reply, here is a small practical implementation to make it more clear. 

Sub: To assign JavaScript value in OutSystems local variable using JavaScript.

Sections:

1) Screen consists of

Local Variable - InputValue

Screen Action - Show, ShowUpdateValue 

Expression Widget - MsgExp, UpdatedMsgExp


2) Input widget - You can set the input widget style = 'display:none;' as per your requirement.

3) Show Button Action -

4) Show Updated Value Button Action:

5) Final Output: (Link)


Hence you can use the assigned JavaScript value i.e. by local variable InputValue

Hope you understood my explanation. Let me know if you have any questions!


Regards,

Benjith Sam

Solution

You may want to call change() after setting the value in case you need to do something on onChange()

SyntaxEditor Code Snippet

$(""#"+input_id+""").change();


Benjith Sam wrote:

Hi Sachin,

In addition to Marcelo Ferreira reply, here is a small practical implementation to make it more clear. 

Sub: To assign JavaScript value in OutSystems local variable using JavaScript.

Sections:

1) Screen consists of

Local Variable - InputValue

Screen Action - Show, ShowUpdateValue 

Expression Widget - MsgExp, UpdatedMsgExp


2) Input widget - You can set the input widget style = 'display:none;' as per your requirement.

3) Show Button Action -

4) Show Updated Value Button Action:

5) Final Output: (Link)


Hence you can use the assigned JavaScript value i.e. by local variable InputValue

Hope you understood my explanation. Let me know if you have any questions!


Regards,

Benjith Sam

Yeah it is working Thank you :)


Hi there

The solution above works, but I need to do it within a logic server action (hence no UI input boxes available).

How do I go about that?

Dylan Heunis wrote:

Hi there

The solution above works, but I need to do it within a logic server action (hence no UI input boxes available).

How do I go about that?


Hi Dylan Heunis,

Sorry for the late response. As per the above stated solution it gets executed in the server action i.e. the JavaScript code in which the JS value is assigned to the OS local variable is written in the server side,  I mean on the Button onClick action flow. Here the input widget on the UI is just a medium through which we are assigning the JS value to the Input widget container (local variable) by which it is mapped. In your case you can hide the input box from the UI-end.


Hope you understood my explanation :-)


Thanks & Regards,

Benjith Sam

Hi everyone;

How should we proceed if, instead of a value, one needs to pass a whole list (or even a list of lists) from a JS to an OutSystems Local Variable?

Thank you all,

Best regards;


Telmo Oliveira

Telmo Oliveira wrote:

Hi everyone;

How should we proceed if, instead of a value, one needs to pass a whole list (or even a list of lists) from a JS to an OutSystems Local Variable?

Thank you all,

Best regards;


Telmo Oliveira

Serialize into a json string.