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.


#15

Thank you so much! you nailed it!


#17

Thanks @Noga , that was the fix.


#18

Thank you for this thread! I having a heck of a time figuring out why Axure was resetting my global variable.

For me, I was setting the global variable in a common form I could access from multiple pages, then using the OpenLink interaction with the target ā€œBackā€ to return to the page it was called from.

This was handy to quickly remember the page the common form was accessed fromā€¦ but because I now realize it resets global variables set in said formā€¦ Iā€™ll need to figure out a new way to do this.