cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
seadude
Level 10

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
Super User
Super User

Re: Help Understanding Set() and UpdateContext({})

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.

Re: Help Understanding Set() and UpdateContext({})

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.

 

3 REPLIES 3
Super User
Super User

Re: Help Understanding Set() and UpdateContext({})

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.

Re: Help Understanding Set() and UpdateContext({})

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.

 

seadude
Level 10

Re: Help Understanding Set() and UpdateContext({})

Hi @KeithWhatling 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
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 4 members 3,944 guests
Recent signins:
Please welcome our newest community members: