595
Views
11
Comments
Solved
WEB Local Storage Javascript
Question

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!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

@Paulo,

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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Jeroen,

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

2019-03-18 10-26-38
Jeroen Vormer

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.........

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

2019-03-18 10-26-38
Jeroen Vormer

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 ?!?!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

2025-01-07 17-06-54
Paulo Cação
Champion

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!

2019-03-18 10-26-38
Jeroen Vormer

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....


2025-01-07 17-06-54
Paulo Cação
Champion

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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

@Paulo,

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

2019-03-18 10-26-38
Jeroen Vormer

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!

2023-12-28 16-01-00
Sérgio Trindade

Jeroen Vormer wrote:

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!

 Hi, did you get an work-around for that problem. I'm having the same issue.

 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.