cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SteveEZ
Frequent Visitor

Issue - Dropdown within Gallery causing first row unexpected behavior

Hello All, I am relatively new to Power Apps, and this is my first time on this forum. I believe that I’ve discovered a bug in Power Apps while trying to develop a Ranking app for my team. The requirements of the app are as follows:

  1. Items to be ranked will be listed in a gallery. Any number of items (up to 50, or more) can be listed in the gallery.
  2. Items in the gallery can be given a numerical rank value, or can be left blank.
  3. The rank values are in ordinal numbers, with 1 being 1st (highest rank), and N (the total number of items in the gallery) being Nth (lowest rank). Blanks are given no rank.
  4. An item in the gallery can have one distinct rank value (duplicate values are not allowed).
  5. The user can rank any quantity of items in the gallery up to and including all N items, or can leave any quantity of items unranked (i.e. blank), and can select any rank value for any item in the gallery in any order.

These requirements are being implemented in the app code using a vertical gallery and a dropdown within the gallery.  The code in the OnChange property of the dropdown control is used to regenerate the list in the dropdown after a dropdown selection is made such that the selected value is removed from the dropdown list (and thus cannot be selected again on another item in the gallery). The user is also given the option of blanking out a previously selected value, or to replace a previously selected value with a different value from the dropdown list, so the OnChange code accommodates those optional user actions as well. 

 

The implemented code works for all rows of the gallery except the first row of the gallery, where the dropdown selected value is not removed from the dropdown list of values upon regeneration of the Drop down list values. This then allows a duplication of values in the gallery, which breaks the fundamental rule of distinct ranking for the gallery items. Since all code for a control embedded within a gallery is supposed to work on all gallery items identically, I don’t know how to troubleshoot this issue further, and have therefore concluded that this must be a bug with the interoperability of the Drop down control (specifically, the OnChange code) and the Gallery control.

 

If anybody on this forum can provide a work-around for this issue (per the stated requirements for this functionality), or if there is something missing in the code that is causing this unexpected behavior, I’d appreciate the assistance. If this is a bug, I'd appreciate a heads up from the Microsoft Development team and a timeline to fix it.

1 ACCEPTED SOLUTION

Accepted Solutions
SteveEZ
Frequent Visitor

After a LOT of trial and error and various alternative experiments, I finally
identified the issue and resolved it on my own.

 

The root cause of the issue is that the data to be populated in the drop down
items CANNOT be retrieved from the data source from within the OnChange property
of the Drop Down control. This is not a bug within Microsoft PowerApps, but
instead is simply poor documentation within Microsoft's PowerApps documentation
in that this is not identified as a limitation of the OnChange property.

 

The solution to this issue is to remove from the OnChange property any code that
retrieves data from the data source of the Drop Down control. Instead, use the
OnSelect property to retrieve the required data in the current state from the
the current state of the app (i.e. the gallery in my instance) and populate that

data in the Drop Down control items. Then use the OnChange property to make

the required changes to the data source (after a choice of a value has been made

by the user).

 

The fix to my particular issue was to create the collection of currently
available values in the OnSelect property of the Drop Down control by checking
the current state of the gallery, and populate that collection into the Drop
Down via the Items property. When the user clicks the Drop Down chevron, the
collection is calculated via the OnSelect property and is populated into the
Drop Down's items via the Items property. The OnChange property is then used
exclusively to choose a particular value and populate it into the
gallery. The end user does this iteratively (OnSelect > OnChange), and with
each choice the remaining available Drop Down values are calculated on the next
OnSelect of the Drop Down control of another item in the gallery.

 

I wish that proper usage of the OnSelect and OnChange properties of the Drop
Down control had been described in Microsoft's documentation - would have saved
me a lot of time.

View solution in original post

3 REPLIES 3
SteveEZ
Frequent Visitor

Here are some screenshots of the app with Rank Value drop down selections visible:

SteveEZ_1-1655210774887.png

Note that the drop down code from the 2nd to the Nth row of the gallery functions correctly:

SteveEZ_2-1655211254361.png

But the dropdown does not function correctly for the 1st row:

SteveEZ_4-1655211575675.png

When the rank value of "4" is selected for the first row, that value is not removed from the drop down list, but instead persists in the drop down list (see red circled "4" in the drop down list) as though the OnChange code of the drop down had not been executed. Yet the OnChange code functions correctly for all other rows in the gallery.  Why does only the first row behave in this manner?

 

 

SteveEZ
Frequent Visitor

The chosen drop down value is stored in a label control (Debug_ItemRank) for the given gallery row item as the displayed rank value for that gallery item.

 

Here is the code to seed the values in the drop down control via App OnStart, including placing a blank at the beginning of the collection:

// Create the ValuesAvail collection:
Clear(colValuesAvail);
Patch(
colValuesAvail,
Defaults(colValuesAvail),
{Value: Blank()}
);
ForAll(
Sequence(CountRows(colRequestItems)),
Collect(
colValuesAvail,
Value
)
);

 

And here is the OnChange code of the drop down that lists the values to choose from:

// There are only 4 possible combinations:

// 1) If the displayed number is blank and the dropdown selection is blank,
// then do nothing.

If(
// 2) If the displayed number is not blank and the dropdown selection is
// blank, place the displayed number back into the ValuesAvail collection
// and set the Ranking value of the selected item to a blank:
And(
Not(
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
).Ranking=0
),
ComboBox1.Selected.Value=Blank()
)
,
Set(varLogicBranch, 2);
// Add the displayed number to the colValuesAvail collection and
// re-sort the collection values for the dropdown to reference:
Patch(
colValuesAvail,
Defaults(colValuesAvail),
{Value: LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
).Ranking}
);
ClearCollect(
colValuesAvail,
{Value: Blank()},
Sort(
Filter(
colValuesAvail,
Not(
Value=Blank()
)
),
Value,
Ascending
)
);
// Patch the selected Request Items collection record Ranking
// value with a zero (representing a Blank).
Patch(
colRequestItems,
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
),
{Ranking: 0}
)
,

// 3) If the displayed number is blank and the dropdown selection
// is not blank, set the Ranking value of the selected item
// to the dropdown selection, and remove the dropdown selection
// from the ValuesAvail collection:
And(
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
).Ranking=0,
Not(
ComboBox1.Selected.Value=Blank()
)
)
,
Set(varLogicBranch, 3);
// Patch the collection record's Ranking value with the
// dropdown selection:
Patch(
colRequestItems,
LookUp(colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
),
{Ranking: ComboBox1.Selected.Value}
);
// Remove the dropdown selection from the items in the dropdown
ClearCollect(
colValuesAvail,
{Value: Blank()},
Filter(
Sort(
Filter(
colValuesAvail,
Not(
Value=Blank()
)
),
Value,
Ascending
),
Not(
Value=ComboBox1.Selected.Value
)
)
);
,

// 4) If the displayed number is not blank and the dropdown
// selection is not blank, swap the numbers by first
// temporarily storing the selected item's Ranking value into
// a variable,
// then setting the Ranking value of the selected item to
// the dropdown selection, and finally removing the dropdown
// selection from the ValuesAvail collection and patching
// the temporarily stored number from the variable into the
// ValuesAvail collection.
And(
Not(
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
).Ranking=0
),
Not(
ComboBox1.Selected.Value=Blank()
)
)
,
Set(varLogicBranch, 4);
// Store the selected item's Ranking value into
// a temporary variable:
Set(
varTempCurrentItemRank,
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
).Ranking
);
//Patch the collection record with the dropdown selection
Patch(
colRequestItems,
LookUp(
colRequestItems,
ItemID=Value(
Debug_ItemID.Text
)
),
{Ranking: ComboBox1.Selected.Value}
);
// Remove the dropdown selection from the items in the dropdown
Remove(
colValuesAvail,
ComboBox1.Selected
);
// Add the displayed number to the items and re-sort the items
// for inclusion in the dropdown
Patch(
colValuesAvail,
Defaults(colValuesAvail),
{Value: varTempCurrentItemRank}
);
ClearCollect(
colValuesAvail,
{Value: Blank()},
Sort(
Filter(
colValuesAvail,
Not(
Value=Blank()
)
),
Value,
Ascending)
);
)

 

Again, all of this code works correctly EXCEPT for the first row of the gallery. I've had other users execute this code in their own environment in order to exclude a possible environmental misconfiguration on my part, and they observe the exact same aberrant behavior. Hoping that somebody from the Microsoft Dev team can explain this.

SteveEZ
Frequent Visitor

After a LOT of trial and error and various alternative experiments, I finally
identified the issue and resolved it on my own.

 

The root cause of the issue is that the data to be populated in the drop down
items CANNOT be retrieved from the data source from within the OnChange property
of the Drop Down control. This is not a bug within Microsoft PowerApps, but
instead is simply poor documentation within Microsoft's PowerApps documentation
in that this is not identified as a limitation of the OnChange property.

 

The solution to this issue is to remove from the OnChange property any code that
retrieves data from the data source of the Drop Down control. Instead, use the
OnSelect property to retrieve the required data in the current state from the
the current state of the app (i.e. the gallery in my instance) and populate that

data in the Drop Down control items. Then use the OnChange property to make

the required changes to the data source (after a choice of a value has been made

by the user).

 

The fix to my particular issue was to create the collection of currently
available values in the OnSelect property of the Drop Down control by checking
the current state of the gallery, and populate that collection into the Drop
Down via the Items property. When the user clicks the Drop Down chevron, the
collection is calculated via the OnSelect property and is populated into the
Drop Down's items via the Items property. The OnChange property is then used
exclusively to choose a particular value and populate it into the
gallery. The end user does this iteratively (OnSelect > OnChange), and with
each choice the remaining available Drop Down values are calculated on the next
OnSelect of the Drop Down control of another item in the gallery.

 

I wish that proper usage of the OnSelect and OnChange properties of the Drop
Down control had been described in Microsoft's documentation - would have saved
me a lot of time.

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (4,319)