cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MichaB12
Helper I
Helper I

Update Gallery display using variables in Items property

Hi,
I have a problem concerning Gallery display using variables in Items property. 
  • I have a SharePoint Datasource (named MichMich below), with 'Title'(String) and 'Done' (Yes/No) columns.
  • In app OnStart, I set a var 'items' with this formula:

Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)));

  • In my screen I have a Gallery that uses 'items' var in its Items property
  • When selecting an item in this gallery, the OnSelect property create a new variable 'mySelectedItem':
Set(mySelectedItem, ThisItem);
  • There is another gallery using 'mySelectedItem.Rest' to display grouped rows
  • In each row of this second gallery, there is a trrash icon with this code in its OnSelect property:
Remove(MichMich, ThisItem);Select(Button1)
  • the Button1 OnSelect code should update 'items' and 'mySelectedItem' variables:
Select(RefreshIcon);
Set(
mySelectedItem,
First(Filter(items, ThisRecord.Done = mySelectedItem.Done))
)
  • The RefreshIcon OnSelect code just update the 'items' variable (same code as in OnStart):
Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)));
 
In this example, this is what should normally happen:
  • On start, 'items' variable is set with some data: let's say 3 rows with Done=true and 2 with Done=false
  • first Gallery displays 2 rows: one for 'true' with count=3 and one for false with count=2
  • I select the true row
  • 'mySelectedItem' variable is set with the selected item
  • the second Gallery displays the 3 rows contained in 'mySelectedItem'.Rest 
  • I delete one of those rows with the trrash icon
  • it updates the datasource
  • The first gallery updates its display (count=3 -> count=2)
  • then it update my mySelectedItem variable
  • Finally, the second Gallery displayed 2 rows

 

The problem is that the final point never happens: the second gallery is still displaying the 3 rows. 

Why is that happening? How can I fix this?

 

But the thing is that when I manually click on Button1, it updates the display of second Gallery... 

 

I looked at the Button1 code:

 

when I highlight mySelectedItem, PowerApps shows me that it is not updated (count=3) but when I highlight items, I shows count=2.

It looks like the Set function in Button1 does not work. But this is not the case because it works when I manually click on the button.

 

I attached screenshots to illustrate my above example, there is in order:

  • initial state
  • state after clicking on the trrash icon
  • state after clicking on button

 

If anyone could have a try with this, I would really like to understand why is this happening. Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @MichaB12 ,

 

This is because the order of execution of the formula is different from what you think.

 

What do you think the order of execution of the formulas:

When you press the trash Icon -> Delete Record -> Execute the "Select(RefreshIcon)" formula of button1 ->Execute the "Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))" formula of RefreshIcon -> Execute the "Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))" formula of button1

 

Its true execution order:

When you press the trash Icon -> Delete Record ->Execute the "Select(RefreshIcon)" formula of button1 -> Execute the "Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))" formula of button1->Execute the "Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))" formula of RefreshIcon

 

In short , you think you update the mySelectedItem variable after you update the items variable, but it first updates the mySelectedItem variable and then updates the items variable. 

Since the items variable did not change (refresh) at the beginning, although mySelectedItem is updated, it is the same as before.

 

So,  this is your original formula:

button1 onselect:

Select(RefreshIcon);Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))

RefreshIcon onselect :

Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))

 

You should modify the formula like this:

button1 onselect:

Select(RefreshIcon)

RefreshIcon onselect :

Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)));Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))

 

This will ensure the order of execution.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

View solution in original post

1 REPLY 1
v-xiaochen-msft
Community Support
Community Support

Hi @MichaB12 ,

 

This is because the order of execution of the formula is different from what you think.

 

What do you think the order of execution of the formulas:

When you press the trash Icon -> Delete Record -> Execute the "Select(RefreshIcon)" formula of button1 ->Execute the "Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))" formula of RefreshIcon -> Execute the "Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))" formula of button1

 

Its true execution order:

When you press the trash Icon -> Delete Record ->Execute the "Select(RefreshIcon)" formula of button1 -> Execute the "Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))" formula of button1->Execute the "Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))" formula of RefreshIcon

 

In short , you think you update the mySelectedItem variable after you update the items variable, but it first updates the mySelectedItem variable and then updates the items variable. 

Since the items variable did not change (refresh) at the beginning, although mySelectedItem is updated, it is the same as before.

 

So,  this is your original formula:

button1 onselect:

Select(RefreshIcon);Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))

RefreshIcon onselect :

Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)))

 

You should modify the formula like this:

button1 onselect:

Select(RefreshIcon)

RefreshIcon onselect :

Set(items, AddColumns(GroupBy(MichMich, "Done", "Rest"), "count", CountRows(Rest)));Set(mySelectedItem,First(Filter(items,ThisRecord.Done=mySelectedItem.Done)))

 

This will ensure the order of execution.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (50,973)