How to pass local variable value to another screen in mobile apps

How to pass local variable value to another screen in mobile apps

  

Hello, i want to ask a question:

Case: i want to pass a local variable value from screen A to screen B in mobile apps, (as you know when the screen is destroyed the local variable value will return to it's default value), so when i go back to screen A, i can pass back the local variable value to screen A.

question: is there any ways to do that?, is a 'Global Variables' or variables that can go through screen is available in mobile?

Thank you!

Hi joshua,

A mobile Screen can have input parameters, so when you call it from another page, you can pass values.
Another way is to use a JavaScript variable. As the Mobile application is a "one page" application, JavaScript variables are common to all the pages (more or less).

Cheers.

Eduardo Jauch wrote:

Hi joshua,

A mobile Screen can have input parameters, so when you call it from another page, you can pass values.
Another way is to use a JavaScript variable. As the Mobile application is a "one page" application, JavaScript variables are common to all the pages (more or less).

Cheers.


Hi Eduardo,

thank you for your answer, now i can pass value between screens with input parameters.

but i got one more question: i make a shortcut to screen A in bottom bar block and menu block, and they also need that Screen A's input parameter value. How can i pass the value into bottom bar block or menu block? 

thank you!

Hi Joshua,

The BottomBar and Menu blocks do not have access to the Input Parameters of the screen they are placed on, so you have a few options:

  • You can go with the JavaScript variables idea Eduardo mentioned (I don't think I've tried doing that before, he might be able to help you better there)
  • Modify those two blocks to receive a mandatory Input Parameter that will hold the value you want to place on Screen A's local property. On all screens you will now have to explicitly assign to the Block's new Input Parameter the value you will want the local property to have, which would be as simple as assigning the Screen's input parameter you've created before. Be aware that if the user presses the back button, this will bypass your "memory" mechanism and navigate back without the said local variable value
  • The simplest option would probably be to just store the value in an LocalStorage Entity instead, and have your Screen A fetch it when it loads.

Hope this helps

Solution

Joshua Benaya wrote:

Hi Eduardo,

thank you for your answer, now i can pass value between screens with input parameters.

but i got one more question: i make a shortcut to screen A in bottom bar block and menu block, and they also need that Screen A's input parameter value. How can i pass the value into bottom bar block or menu block? 

thank you!

Hello Joshua,

Besides what Jorge said, this requirement is a bit "odd".

Usually we have an input parameter on a page to enable open the page and pass a value that can change each time you call the page. The most common example is: You want to open a detail page from a list page, passing the id of the item you clicked. Every time you do that, the id can be different, than the input parameter.

And that is the reason why you don't put Detail Pages in Menus. Because if the input parameter depends on user input, you would be required to update the menu block to take into account the new value, every time.

If your page "needs" an input parameter, the reason is that you depend on some information that will be generated in the caller page. The problem is the same: you have to update the block where the sortcut is, passing the new value for each, every time the value changes.

In this particular case, saving the information to local storage instead, seems a good approach, as it is fair simple to deal with it.

If you don't want to deal with an entity and prefer to do something similar to a "session variable" from web, the way to go is to create a javascript variable and than use it normally.

Hope this helps.
Cheers.

EDIT: I have removed the example as it is with a strange behaviour and I was not able to identify the problem yet.

But here you have how to do what you need with local storage (safer)
https://success.outsystems.com/Documentation/10/Developing_an_Application/Use_Data/Maintain_State_while_Navigating_across_Screens


Solution

@everyone


thank you for the answers, sorry for late reply

the input parameter way works fine for me,

and also i realize that passing value into the bottom bar or menu bar is not very effective, so i think it is way effective to store the value in local storage.


Thank you