How to clear Client Variables

I created 2 screen, Screen A and B. My default screen is Screen A 

Screen A - To allow user to make some request. 

When initialize, it will check if user had login (I created a client variable login which is a Boolean and by default is False) if the value of the login is false it will jump to Screen B to get user to login first.

Screen B - Login screen.

Do note this is not outsystems default login page but a custom login page. 

If login is successful it will assign the login client variable to True and jump back to Screen A. If user try to click on the Screen B again from the menu it will abort as the login client variable is already true so it will remain in Screen A.

Everything seem perfect, until i close the apps and re-open again. I am expecting the apps to ask the user to login again but it did not the client variable login remain as True due to the session still active.

I first started by using local variable but it seem that local variable is only visible to the individual screen so it will not work with what i want to do

I also did think of Storing the logic Boolean variable in local entity, but seem a bit overkill , i therefore turn to Client variable as it is accessible by all screen.

Appreciate someone can advise me how to clear the client variable each time i close the apps or each time i re-open the apps. 

Thank you in advance :)

Champion
Solution

Hi Jerah, 

Client Variables reset to their default values when the user signs out of the app or when the platform signs out the user automatically. So, It can not  clear the client variable each time when we close the apps or each time re-open the apps. Whole purpose of client variable is to cache the data, So that It can be shared across the different apps in the same environment when the user provider of app is same and running in same environment. But you want to clear the client variable each time when app is closing or opening, It is contradicting it's nature. 

if You want to keep with your way - 

          1. At OnInitialize of screen your flow check the value of client variable and set it's value to true when it is login and  redirect to screen according to value.

          2. use OnApplicationReady to intialize client variable - Check documentation.

          Assign False in your client variable (i.e Login) in OnApplicationReady action flow. It will help you to send you at screen B each time when you open the app. 


Some supportive link- 

https://success.outsystems.com/Documentation/11/Managing_the_Applications_Lifecycle/Secure_the_Applications/Configure_App_Authentication

https://success.outsystems.com/Documentation/How-to_Guides/Logic/How_to_add_extra_logic_to_Users'_login?_gl=1%2A17dbgkp%2A_ga%2AMTg5NDU5MjA3LjE2MTY2NDQ5ODY.%2A_ga_ZD4DTMHWR2%2AMTYyMzU4NDI4MS40MTkuMS4xNjIzNTg2NTA1LjUz

https://www.outsystems.com/forums/discussion/26974/custom-login/


Hope this help,

Cheers

Hi Jerah,

You can update client variable and set it to false again once closing the app by using below steps.

  1. Create a client action under BottomBar block called UpdateClientVaribale and assign login client variable to False.
  2. Now write below Javascript code to update the Login client variable to False by calling the same client action inside OnReady of BottomBar Block. It will change the client variable to False again once you close the application.


Cheers,

Dileep

Is it valid also when the user closes the browser?


Hi Jose,

For Browser or Reactive Web App,  need to verify, This is working for Mobile Application where we close the application.

Champion
Solution

Hi Jerah, 

Client Variables reset to their default values when the user signs out of the app or when the platform signs out the user automatically. So, It can not  clear the client variable each time when we close the apps or each time re-open the apps. Whole purpose of client variable is to cache the data, So that It can be shared across the different apps in the same environment when the user provider of app is same and running in same environment. But you want to clear the client variable each time when app is closing or opening, It is contradicting it's nature. 

if You want to keep with your way - 

          1. At OnInitialize of screen your flow check the value of client variable and set it's value to true when it is login and  redirect to screen according to value.

          2. use OnApplicationReady to intialize client variable - Check documentation.

          Assign False in your client variable (i.e Login) in OnApplicationReady action flow. It will help you to send you at screen B each time when you open the app. 


Some supportive link- 

https://success.outsystems.com/Documentation/11/Managing_the_Applications_Lifecycle/Secure_the_Applications/Configure_App_Authentication

https://success.outsystems.com/Documentation/How-to_Guides/Logic/How_to_add_extra_logic_to_Users'_login?_gl=1%2A17dbgkp%2A_ga%2AMTg5NDU5MjA3LjE2MTY2NDQ5ODY.%2A_ga_ZD4DTMHWR2%2AMTYyMzU4NDI4MS40MTkuMS4xNjIzNTg2NTA1LjUz

https://www.outsystems.com/forums/discussion/26974/custom-login/


Hope this help,

Cheers

Hi Jerah,

Rahul was right, It is contradicting its nature.
Not sure though, if you are developing on a Mobile or Web applications. But to give you insight about this, I think using a Session variable is the right variable for your scenario here.

You may refer to the difference of the two variables:

Hope this will help you.

Cheers!

Marco

Hi Jerah, 

You may use the below javascript code in OnApplicationReady to clear all client variables. 

localStorage.clear();

Regards,

Jaya kumar R

Thank you all for all your input.

I had tested all your suggestion and  i found that @

Rahul Kumar solution help me to resolve my problem.

Adding a system event OnApplicationReady to the Client Actions under the Logic side allow me to clear the client variable when the application start. 

If i try to add the clear client variable in other area , it will not work as the client variable will keep getting reset. 

Thank you very much , really appreciate you all for helping me to move forward. I had been stuck in this logic for a while hahaha

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