How to access site or session variable value in java script out systems?

1.6k views Asked by At

i want to use session and site properties in java script in out systems.

what is the way to access them in my code? below is my tried code. weeknumber is session variable which is having some default value. "alert(Session.weeknumber);" and am getting "Uncaught ReferenceError: Session is not defined" error.

2

There are 2 answers

0
Abdulhakeem On

In Outsystems you have an access to the session and site properties. I did not get your questions very well but I will give you an example and hopefully will clarify something for you on how to use it.

Let's say you have a page and you want to alert the user after the document is loaded.

1) Add an expression to the page.

2) Change the "Escape Content" property of the expression you added to "NO".

3) Add the following to the "value" property

"<script type='text/javascript'>
    $(document).ready(function(){
        alert('"+Session.weeknumber+"');
    });
</script>"
0
David Foley On

No problem.

Similar answer, but you can just instantiate client side instances of those variables using an un-escaped expression with a value like:

"<script>" + 
         "var weekday = '" + Session.Weekday + "';" +
         "var otherVariable = '" + Session.OtherVariable + "';" +
"</script>"

Then, when you want to update the value of the Session Variable/Site property, just use js/jQuery to set the value of an invisible input box, and then submit it back to the server. If you need to refresh the client side values from the server to the client again, just ajax refresh the un-escaped expression. Let me know if you want more detail.