cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
virakones
Resolver II
Resolver II

Gallery Selected Item not refreshing, affecting Button Displaymode logic

I have an app that will allow users to create a record in one gallery, then patch some child records in a second gallery and then submit the parent record to the data source. The submit button is disabled if the child records are empty but running into issues where even though a child record is patched, the submit parent record button display mode is still showing disabled unless "refreshed" by selecting another record in that parent gallery.

__________________________

 

I have galParent and galChild

I have 2 buttons, btnSubmitParent and btnSubmitChild

When you create a parent record it shows up in galParent, then with that selected item, you can create a child record in galChild.

 

the logic for btnSubmitChild is a Patch formula and then includes a refresh

Patch(
        ChildDataverseTable,
        Defaults(ChildDataverseTable),
        {
            LookupParentChild: galParent.Selected,
            Column1: Input1.Text
        }
);
Refresh(ChildDataverseTable);
Refresh(ParentDataverseTable);
Reset(galParent)


the logic for the btnSubmitParent Displaymode:

DisplayMode:

If(
    IsEmpty(galParent.Selected.ChildRecords), 
    DisplayMode.Disabled, 
    DisplayMode.Edit
)


___________

Just a bit confused why even though the child record is created and the parent.selected item is no longer empty, that the button is still disabled.

 

The quirky thing though, is that when you select another parent record and select the previous record, the item is now "refreshed" and btnSUbmitParent works.

What is going here and how can I "refresh" a currently selected item in a gallery?
 

1 ACCEPTED SOLUTION

Accepted Solutions
virakones
Resolver II
Resolver II

@RandyHayes 

I've found a solution. 

The formula that was originally populating my Parent Gallery's Items filtering the data source directly, I've instead changed to a ClearCollect that I've moved to after my submit buttons OnSelect Patch formulas and my dropdown controls OnChange properties and then simply set the gallery to this new Collection.

This way after patching > data source resets > collection is rebuilt > gallery is "refreshed" displaying the latest changes.

Now the DisplayMode property of my main submit button is correct.

View solution in original post

6 REPLIES 6
RandyHayes
Super User III
Super User III

@virakones

I am not completely clear on your logic with the button as to when it should or should not be visible.  But this is most likely based on the Items property of your galleries.  

You do not need to do a refresh on your datasources nor a reset on the gallery.  If your Items properties are correct, the gallery will be dynamic and change accordingly.

So...what are the items properties?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@RandyHayes 
Thanks for taking a look.

That is also what I imagined as well, that the items should dynamically update and, at worst, I add that refresh.

Admittedly, the gallery items of the parent records is a bit more complex than my original post. It is a bunch of dataverse for teams records that are filtered by a dropdown that will Switch data verse views (approved, edited, pending, all). That result is sorted by created date. Then that result is filtered by another drop down where the created date is greater than another dropdown (last 3 days, last 7 days, last 30 days) and finally that is filtered by the user currently logged in. 

Because the new parent record is not assigned a status yet (null field) it should fall under the "All" view.

 

 

galParent Items:

If( 
    User().Email = "SuperUser1@company.com" Or "SuperUser2@company.com",
    Filter(
        Sort(
            Switch(
                cmbStatusFilter.Selected.Value, // this is the status filter dropdown control
                "Approved",
                Filter(
                    Orders,
                    'Orders (Views)'.viewApprovedOrders
                ),
                "Pending",
                Filter(
                    Orders,
                    'Orders (Views)'.viewPendingOrders
                ),
                "Edited",
                Filter(
                    Orders,
                    'Orders (Views)'.viewEditedOrders
                ),
                "All",
                Filter(
                    Orders,
                    'Orders (Views)'.viewAllOrders
                )
            ),
            'Created On', 
            Descending
        ),
        'Created On' > varDate //this will filter by the date dropdown selected
    ),
    Filter( //Else, if not a super user, filter based on below logic
        Filter(
            Sort(
                Switch(
                    cmbStatusFilter.Selected.Value, // this is the status filter dropdown
                    "Approved",
                    Filter(
                        Orders,
                        'Orders (Views)'.viewApprovedOrders
                    ),
                    "Pending",
                    Filter(
                        Orders,
                        'Orders (Views)'.viewPendingOrders
                    ),
                    "Edited",
                    Filter(
                        Orders,
                        'Orders (Views)'.viewEditedOrders
                    ),
                    "All",
                    Filter(
                        Orders,
                        'Orders (Views)'.viewAllOrders
                    )
                ),
                'Created On',
                Descending
            ),
            'Created On' > varDate //this will filter by the date dropdown selected
        ),
        'Created By'.'Primary Email' = User().Email //curent user logged in sees their records
    )
)

 

 

This is a video demo of the experience. As you can see the submit button is greyed out at first because the child gallery is empty (as it should be). I'll add a child record, but the record is still greyed out (should not happen because the displaymode logic is wrong now).  However, once I select a previous record and come back, the displaymode of the submit button is working.

@RandyHayes 

it's also a bit odd but the powerapps studio is confirming that the logic of the button displaymode should be in edit - yet its showing as disabled - is this a bug?

virakones_0-1619120498686.png

 

RandyHayes
Super User III
Super User III

@virakones 

Well, there is an error in your formula and also it can be highly refined.

Here is a simplified version of it that is equivalent:

Filter(
    Sort(
        Switch(
            cmbStatusFilter.Selected.Value, // this is the status filter dropdown control
            "Approved", Filter(Orders, 'Orders (Views)'.viewApprovedOrders),
            "Pending", Filter(Orders, 'Orders (Views)'.viewPendingOrders),
            "Edited", Filter(Orders, 'Orders (Views)'.viewEditedOrders),
            "All", Filter(Orders, 'Orders (Views)'.viewAllOrders)
        ),
        'Created On', 
        Descending
     ),
     'Created On' > varDate &&
     ('Created By'.'Primary Email' = User().Email || User().Email in "SuperUser1@company.com|SuperUser2@company.com")
)

 

Put that in place first and let's see where things are.  Because it is equivalent (except the mistake is fixed) it should not make a difference, but let's see where that takes us and we can go from there.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@RandyHayes 

Wow, I really appreciate the simplified formula, much cleaner - but unfortunately it's still producing the same.

The submit button's displaymode is disabled even though the parent record selected has child records and is not empty. When I click to another record and click back, the button correctly changes to edit mode.

virakones
Resolver II
Resolver II

@RandyHayes 

I've found a solution. 

The formula that was originally populating my Parent Gallery's Items filtering the data source directly, I've instead changed to a ClearCollect that I've moved to after my submit buttons OnSelect Patch formulas and my dropdown controls OnChange properties and then simply set the gallery to this new Collection.

This way after patching > data source resets > collection is rebuilt > gallery is "refreshed" displaying the latest changes.

Now the DisplayMode property of my main submit button is correct.

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 (67,959)