cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

Help Understanding Set() and UpdateContext({})

Hello,
I keep running into this silly issue. Could use some help understanding it.

Issue:

  • There are times when I use Set(var,Blank()) on Screen1, then move to Screen2 and var does NOT update.
  • In these cases, var is black color in the Function Bar on Screen1 and a blue color in the Function Bar on Screen2.
  • Since the var will not set, I have to delete it and change it to UpdateContext({var:true}) on Screen2 in order for things to work.

Why? I thought that if I declare a var with Set(), its scope is universal. Why am I getting hung up here?

Thank you

2 ACCEPTED SOLUTIONS

Accepted Solutions
wyotim
Resident Rockstar
Resident Rockstar

That is odd indeed. Have you tried looking at the Global Variables section and looking at the Definitions, Uses, and Indirect Uses? That would help in tracking the places that could be calling it, just to ensure it isn't being called somewhere unexpected. Otherwise, something strange is going on as I am pretty sure Set is global in scope.

View solution in original post

Anonymous
Not applicable

Just to clarify that a veriable declared with Set called var and a variable declared with UpdateContext called var will be two different variables.

 

You cannot change a Set() global vairable with a local UpdateContext({}) call.

 

Recomendations from the coding guidlines suggest that global variable names get a glo prefex and locals get a loc prefex so a Set() variable called var becomes gloVar and a local UpdateContext becomes locVar.

 

Hope this helps.

 

View solution in original post

3 REPLIES 3
wyotim
Resident Rockstar
Resident Rockstar

That is odd indeed. Have you tried looking at the Global Variables section and looking at the Definitions, Uses, and Indirect Uses? That would help in tracking the places that could be calling it, just to ensure it isn't being called somewhere unexpected. Otherwise, something strange is going on as I am pretty sure Set is global in scope.

View solution in original post

Anonymous
Not applicable

Just to clarify that a veriable declared with Set called var and a variable declared with UpdateContext called var will be two different variables.

 

You cannot change a Set() global vairable with a local UpdateContext({}) call.

 

Recomendations from the coding guidlines suggest that global variable names get a glo prefex and locals get a loc prefex so a Set() variable called var becomes gloVar and a local UpdateContext becomes locVar.

 

Hope this helps.

 

View solution in original post

Hi @Anonymous and @wyotim, I now understand the areas you brought up. Thanks for the best practices of looking at "uses" and the glo and loc prefixes. Thats good stuff.

I was missing the part that Set(varThing,true) and UpdateContext({varThing:true}) are SEPARATE VARIABLES even though they are allowed to be named the same.

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (106,823)