How to know if a value has been changed in a collection in PowerApps?

116 Views Asked by At

I have built an editable gallery which is populated and jandled by a collection - MyDataCollection. How can I check if any changes are made into the gallery, as I want to restrict the users from navigating if they haven't saved the changes.

I have already tried comparing two collections by creating a copy of the original one, but that is taking so much time (as my collection size is 15x18). Can you please suggest any better approach.

Thanks in advance.

2

There are 2 best solutions below

0
Sam Nseir On BEST ANSWER

An approach you can take is to add a hidden toggle control into your Gallery. Set its Default value to something like:

Or(
  ThisItem.Status.Value <> dropDown1.Selected.Value,
  ThisItem.'Numeric Property' <> Value(txtNumericBox.Text),
  Text(ThisItem.'String Property') <> Text(txtStringBox.Text),
  If(ThisItem.'Bool Property' = true, true, false) <> checkbox1.Value
)

This toggle will toggle on for each row that has a change (and toggle off when undone). You can then count the rows that have had a change with:

CountRows(Filter(yourGallery.AllItems, toggleModified.Value))
0
Sumit Singh On

Inspired by Sam Nseir's Answer I found one more interesting workaround.

You can add the following code on OnVisible property on the screen

UpdateContext({ GalleryIsChanged: false})

and set the OnSelect property of Gallery as

UpdateContext({ GalleryIsChanged: true})

So whenever any change is done GalleryIsChanged is changed to true, hence whenever the user was trying to navigate I was checking this variable

If(GalleryIsChanged, <My Custom Error Message>)

and resetting its value whenever a user is navigating