Global Variables Reset On Page Load


#1

When I set a global variable upon navigation away from a page, I can tell that it works and is being set; however, when the next page loads, the variable is reset to unknown. This is for a team project. Any ideas on what is going on?


#2

Try setting the global var = 0 or any initial value. Reset it back to that value once the page load trigger happens. This will fix your issue. A link to your prototype can help in giving you a better response.


#3

If I understand what you’re trying to do, it appears to work fine. I have attached a sample RP file that does what you say.
GlobalVariableNavTest.rp (81.4 KB)


#4

But I am setting the value from an interaction … but when i go to another page where i want tuse the newly set value the variable has reset and thats where the problem lies.


#5

Hi!

Navigating from one page to the other will not reset global variables unless you are specifying the go-to page by using a URL rather than selecting it from the list of pages in the Open Link in Current Window command. Global variables will not carry over to the new page if you navigate to it using a URL.

If that’s not the case, in the prototype’s left-hand site map (within the browser) there is a “(x) console” tab. If you click that it will show you the values of your global variables. Use that to verify that the global variable sticks around upon navigation.

If the variable value changes upon page navigation, there is likely some code that is changing it. Also in the “(x) Console” tab is a “trace” of all executed commands. Hit Ctrl+S in your browser and search for “set value of variableName” (where variableName is the name of your variable) to see if some code somewhere is setting it.


#6

If @josephxbrick hasn’t solved your problem, you might want to upload a sample .rp file for us to look at.


#7

I had the same issue and managed to solve it.
The problem occurs if you first open a page (Open Link in Current Window) and then set the variable. In the “(x) console” you see the variable value change momentarily to what you had set, and then it immediately changes back (using Chrome browser).
Switching the order, i.e. first setting the value and then opening the page, fixed the problem.


#8

I had a problem with a self-reseting variable. It behaved strange.

Now I understand why.
The problem was I was regenerating single page only. After I generated the whole project, issue was resolved.

(They are named global variables with a reason. :slight_smile: )

Maybe this experience would be of help to someone.


#9

THX. That was the fix.


#10

:clap::clap:
I did exactly the same stupid me, and could not figure out why that happens.
That’s why I love this forum!

Keep sharing!:hugs:


#11

Hi! I am having the same issue and I can’t understand the ‘solution’ you mentioned here.
Could you give me more details?

thank you
Rachel


#12

Just regenerate with the comand Ctrl+O. :slight_smile:


#13

This solved the problem for me–not navigating by URL, but rather direct page reference.


#14

I have the same issue, but I don’t want to load the page from a direct page reference. I’m loading my pages through their name on the navigation which is an item in a repeater (my menu). Unless anybody knows another way to open a page by variable name… At the end I will have to remove the repeater.