Yesterday, I was scratching my head trying to figure out why a value I stored in a variable was not displayed correctly in the text box.
Turned out I was doing this kind of thing:
I was setting a context variable in one place, and I was setting a global variable in another. Both variables had the same name. Then I was using that variable for a text control:
Interesting, by the way, that context and global variables can have the same name without causing an error. But, if you were to guess, which value do you think would be displayed in the text control in this scenario?
The answer is – it’s the context variable that’ll be displayed there.
Why? Quite frankly, I may not be able to explain what’s happening behind the scene in the Canvas Apps.. Would be great if we could debug them somehow But the best intuitive explanation seems to be that context variables are “closer” to the place than global ones, so I’ll just stick to that.
The end result, though, is that this whole scenario is not extremely obvious. There are no warnings, there are no errors.. everything is supposed to work, but it does not, and you are getting a wrong value (or, worse, an empty value) from a variable.
Well, if you find yourself observing those symptoms, check the scope of your variables and make sure you are not mixing global and context scopes. It might be exactly the problem.