WEB Local Storage Javascript

  

Dear All,


in a preparation of a WebScreen i can set a local-storage-variable you can find in the Chrome-developers-console with javaScript:


Does anyone know how to get a local-storage-variable? (Without using a hidden field on the screen)....


Thanks!

Hi Jeroen,

What are you trying to achieve? Why are you using JavaScript at all?

Hi Kilian,

i'm using an external plug-in which is completely based on javascript.
I can set the values/variables which are needed within this plugin, so that's OK.

While using the plugin (runtime) the local storage variables are changed and i need the new values for processing further in OutSystems........

That said, sometimes it can be handy to alter local (Outsystems) variables in a (screen-)action using javascript.
Last week i needed the acsii-value of a character. OutSystems doesn't have a build-in function for that, only the other-way-around. In JavaScript it's very easy.........

Well, when using JavaScript for Web Apps, keep the client-server model in mind. Any OutSystems code in Screen Actions (and Server Actions) runs on the server, so in order for them to have access to something you do in JavaScript, you need to pass it to the server, which must be done via things like hidden inputs.

So I read on other posts :-(

The only thing I find very strange that I can set the variables, but I cannot get the same variables ?!?!

Hi Jeroen,

Not sure what you mean. Setting and getting the local variables can be done via JavaScript, which is executed client side. However, as soon as you want to use the local variables server side, you need to transfer them from the client to the server. Note this has very little to do with OutSystems specifically, but is a result of a client-server architecture.

Hi Jeroen,

Yes, you can get the variables, using something like that:

Put Variable (As you use):

localStorage.setItem('_NSCaseId', nsId);

Get Variable:

localStorage.getItem('_NSCaseId');


Regards!

Paulo Cação wrote:

Hi Jeroen,

Yes, you can get the variables, using something like that:

Put Variable (As you use):

localStorage.setItem('_NSCaseId', nsId);

Get Variable:

localStorage.getItem('_NSCaseId');


Regards!


Hi Paulo,


i think i cannot address my local variable within my javascript.

I use:

with:

SyntaxEditor Code Snippet

localStorage.setItem('zipcode', '"+ GetCustomersByUserId.List.Current.Customers.Postcode +"');

But when i need it back this does work:

SyntaxEditor Code Snippet

var zip = localStorage.getItem('zipcode');

But this doesn't:

SyntaxEditor Code Snippet

" + zipcodeTest + "= localStorage.getItem('zipcode');


The only thing that's working is using a hidden input-field, but that is not usable in my situation.

And also, I still am very curious because a setItem does work for local variables, but a getItem doesn't....


Hi Jeroen,

If you have a variable in OutSystems, you cant assign a value from Javascript (in this case, from a local storage), because the variable in Outsystems are defined in the server side, and you try to assign a value from client side. 

Regards

Solution

@Paulo,

Erm, yes, that's what I already said above ;)

Solution

I understand. Then I have to find a way to alter local variables, because in my case there isn't a build-in function which is useful.

Thanks all!