Stuart
Stuart

Reputation: 1151

PowerApps global variable not updating when record changed

I have a Canvas app with three pages.

Page 1 has a gallery listing records. When a user selects an item in the gallery the following is executed

Set(SelectedRecord, ThisItem); 
Navigate('Page 2',ScreenTransition.Fade);

Page 2 has a label with

Text = SelectedRecord.Field1

and a link to open page 3

Page three has a form with the same dataset a the Gallery on page 1 and

items = SelectedRecord

and a save button with

OnSelect = SubmitForm(Form_1);
Navigate('Page 2', ScreenTransition.Fade);

My issue is that when the control returns to page 2 the label still shows the old value, I would expect that the global variable would be linked to the dataset and update when changes were made.

Is there a bug here or some process to update the global variable with the updated data?

Upvotes: 0

Views: 2863

Answers (2)

mmikesy90
mmikesy90

Reputation: 981

When you set the SelectedRecord global variable, it will store a copy of the record from the data source. It does not get an automatic update when the data source changes.

You could update the variable explicitly in the Save Button:

OnSelect = SubmitForm(Form_1);
Navigate('Page 2', ScreenTransition.Fade);
Set(SelectedRecord...

Alternatively you could change your logic to only store the record's ID in the variable and use LookUp() in the label. This will reflect the changes made to the data source:

LookUp('DataSource',ID=SelectedRecordID).Field1

Also a suggestion: instead of using a global variable (that can collide with logic on other screens), you could pass the record/id with the Navigate() function like this:

Navigate('Page 2',Fade,{ selectedRecord: <<value>> })

Upvotes: 0

AnkUser
AnkUser

Reputation: 5531

Logically you navigated from Page 3 to Page 2 but you did not give any indication to Page 2, what is should perform. Page 2 is at it's last status (which is coming from Page1 with SelectedRecord.Field1)

When you come from Page 3 you will have to clear Page 2 Text = ""

But make sure you do empty only when you navigate from Page 3

Upvotes: 0

Related Questions