Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Updatecontext variable from a gallery field after adding a record.

I have created an app that collects data stored in a Sharepoint list.  There are three screens.  One with a browse gallery, a detail screen and an edit screen. On the gallery screen there is a link to add records, a navigation control that links to the detail screen.  The detail screen has its item set to BrowseGallery.Selected.  There are three controls.  Back/Cancel, Edit, and Delete/Remove.  The edit screen serves and a new record input form or an edit form depending on which state is set on a context variable.  The problem I have is with adding multiple sequential record.  I set to context variables when the new record button is selected.  frmMode, and sHobbs.  The variable frmMode is set to 1 and sHobbs is set to a fldname of the gallery that represents a field of the dataset (list column).  The first record is added without issue, however, the subsequent records are being populated with the first value.  As an example record 1 sets the column value to the value assigned to sHobbs.  The app returns to the BrowseGallery screen and the last record is displayed in the BrowseGallery.  When the button to add another record is selected UpdateContext({sHobbs:fldEndHobbs}); Navigate(EditScreen1, ScreenTransition.None, {sHobbs:sHobbs, frmMode:frmMode}) is the onSelect formula.  Why is the sHobbs context variable not updating.  The contents of the variable seem to be null.  If I go to the edit screen and select edit then cancel the request the sHobbs is updated with the correct info.  Note that the edit button of the detail screen sets the sHobbs varible also, but, from a datacard value.

Helper V
Helper V

Can you please share some screenshots of this app?


I have posted the requested screen shots awaiting your response. 

Interesting. I don't notice any problems with what you've shared. Regardless, you could try creating global variables using the Set(variable, value) function instead of UpdateContext, which would probably simplify it a bit. Since Set() creates global variables, you don't need to pass them as a context to the screen through navigate, which will simplify that in case there are any problems there. 


Here's some documentation: 


I don't know if this will help, but this is what I'd try next.

Good luck!

- Paul C.
Software Engineer on PowerApps

I tried you suggesstion, but, I didn't work either.  The formula that sets the variable is only executed if another record is to be added.  The variable should be assigned the value of the newly added record from the gallery field that you can clearly see, however, the value being set is the previous sharepoint record.   The only way I have been able to get the variable to update is by navigating to the detail screen, then select the back button.  Then when the new record is added the proper value is assigned to the Start datacard of the input form.  Seems like a flaw in PowerApps.  Does the gallery field initially have a different reference than the one used to display the value?  I even tried to refresh the datasource onVisible before setting the global variable.  Still nothing.  There is definately an issue.



Frequent Visitor

Have you tried setting the value OnChange? So that when the value changes it updates?

Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,808)