web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / BUG? Context Variables...
Power Apps
Answered

BUG? Context Variables not updating correctly in some situations

(1) ShareShare
ReportReport
Posted on by 185

I have the following code on the OnChange of a dropdown control.

 

UpdateContext(
 {
 vSite: ddSiteCode.Selected.Value,
 vDateKey: Value(
 Text(
 dteEffectiveDate.SelectedDate,
 "[$-en-US]yyyymmdd"
 )
 ),
 vSiteKey: LookUp(
 UsersAndSites,
 Site_Code = vSite
 ).Site_Key
 }
);
Set(
 gDebugText,
 Concatenate(
 gDebugText,
 gRET,
 "vSite = ",
 vSite,
 gRET,
 "vSiteKey = ",
 Text(vSiteKey),
 gRET,
 "Lookup = ",
 Text(
 LookUp(
 UsersAndSites,
 Site_Code = vSite
 ).Site_Key
 )
 )
);

vSite and vDateKey get set correctly, but vSiteKey is delayed updating. The Lookup show the correct value.

 

 

For instance if I have these valuse in the collection UsersAndSites:

Site_Code    Site_Key    User_Name

MAC6            154           JohnS

MAC9            728           PhilK

WLDD           503           CarolB

 

I have a multiline textbox control set to display the contents of  global variable gDebugText.

 

The first time I change the dropdown and pick "MAC6".

The second time I select "MAC9".

The thrid time I select  "WLDD".

 

This is what the gDebugText shows. I have seperated each dropdown change with a double line:

==============

vSite = MAC6
vSiteKey = 0
Lookup = 154

==============

vSite = MAC9
vSiteKey = 154
Lookup = 728

==============

vSite = WLDD
vSiteKey = 154
Lookup = 503

==============

 

vSiteKey updated on the second OnChange to what it should have been on the first OnChange.  Every OnChange after that, it would not update and stayed at 154. vSite and vDateKey are updating correctly as are the other context variables in my app, as far as I have found so far.

 

HELP!

Categories:
  • Verified answer
    Meneghino Profile Picture
    6,949 on at

    Try to use the following instead of the first part of your code.  It could be that you need to split into two:

    UpdateContext(
     {
     vSite: ddSiteCode.Selected.Value,
     vDateKey: Value(
     Text(
     dteEffectiveDate.SelectedDate,
     "[$-en-US]yyyymmdd"
     )
     )
     }
    );
    UpdateContext(
     {
     vSiteKey: LookUp(
     UsersAndSites,
     Site_Code = vSite
     ).Site_Key
     }
    ); etc. etc.
  • TML Profile Picture
    185 on at

    That was the fix.  I have always been told to group all the UpdateContexts together.  Any explanation as to why that needed to be broken out?

  • Meneghino Profile Picture
    6,949 on at

    You basically had used the result of a context update in the same context update, so I guess it was dong the updates in parallel (i.e. using the old value in the second statement).  By breaking it out it is more clear that one update is done and the result used in the second update.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard