cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sasrsc1966
Resolver I
Resolver I

OnVisible for the screen vs. Gallery Items when you have a form on the same screen that adds another row

I have a gallery on the left and the form on the right.

Normally when you have a simple relation to one list in SP the list will refresh within seconds of adding a new record with the submit.

In my case, I have a onVisible for the screen, which creates a collection (because I'm adding columns to it...)
The items does a simple filter and sort by.

The submit on the form does a simple SubmitForm to the SP list (not the collection of course)

So how do you suggest you handle refreshing the collection again?
Is it simply, that you paste the exact same code for the onvisible into the onsubmit after submitForm? Like this?

But these seems repetitive - the same clear collect is in the onVisible...

SubmitForm(Form2);

ClearCollect(Reviews,
    ForAll('Test-Reviews' As _r,
        With(
            {
                _vName: LookUp('Test-Vendors',ID=_r.VendorID)
            },
            Patch(
                _r,
                {
                    VendorName: _vName.Title
                }
            )
        )
    )
)

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@sasrsc1966 

Yes, I am stating that if your Gallery is based off a collection, it will never update - it is a snapshot of a table at a time.

I would set the Items property of the Gallery to:

ForAll('Test-Reviews' As _r,
    With({_vName:LookUp('Test-Vendors',ID=_r.VendorID, Title)},
        Patch(_r, {VendorName: _vName})
    )
)

Trying to ClearCollect again is just a performance waste in your app.  The Test-Reviews datasource is already populated with the new information.

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
StalinPonnusamy
Super User
Super User

Hi @sasrsc1966 

 

Place the ClearCollect code on OnSuccess property of the Form. So this is a guarantee to get the data.

 

Note: For performance, we can collect the vendor name only the row/record impacted by this form instead of all. In other words, Get the vendor name when it's empty.

 

 

RandyHayes
Super User
Super User

@sasrsc1966 

First off, you should not have anything after your SubmitForm function in your formula.  Anything you want to happen after submitting should be in the OnSuccess of your form.  Otherwise you risk doing actions when a failure has occurred.  

 

Next, I am not sure what you mean by you are collecting these into a collection because you are adding to them.  If it is essentially based on the datasource, then the datasource is all you need - you don't need to make a duplicate collection in your app.

The way it works is that a datasource is essentially a "collection" already in your app.  This is why, when you submit a form (or any other direct datasource change) that the datasource reflects it immediately.  It's because the internal datasource "collection" is being updated already.  This is why you also never need a refresh on a datasource that you just submitted to...because it is already there.

So, re-collecting the data in the datasource is really just making another copy of the data that is already in the datasource "collection" in your app.

But, you seemed to have a specific reason - can you expand on that more?

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks Randy. Hope your Monday is good. So I understand not having after the onSubmit. Makes sense. If I click "submit" on the form. It does submit and is successful as I see it in the SP List. But I've not switched screen and the Gallery doesn't display the row until I leave the screen and come back to it. Why? Because the gallery is displaying a collection and not a raw SP List. The onVisible is this...

 

ClearCollect(Reviews,
    ForAll('Test-Reviews' As _r,
        With(
            {
                _vName: LookUp('Test-Vendors',ID=_r.VendorID)
            },
            Patch(
                _r,
                {
                    VendorName: _vName.Title
                }
            )
        )
    )
)


the gallery items is this...

Filter(Reviews,TripID=DrpTrips.Selected.ID)


the onSubmit is "working" and inserting a row into Test-Reviews but because I'm not triggering another onVisible it doesn't appear. Is that a little better explained? Here's the screen with the gallery on the left and the form on the right.. The user clicks + (top right), selects a vendor, add a rating, adds an optional comment and clicks submit. When they do that I want the gallery to refresh. But you're saying I shouldn't need to do anything? It should happen. I would 100% agree with you if the gallery was just a simple SP List, but because it's a collection and the collection doesn't refresh except on Visible as I thought (in my simple mind). To be clear - if I edit an existing item, the gallery doesn't reflect the change until I trigger the onVisible code again.

 Region Capture.jpg

RandyHayes
Super User
Super User

@sasrsc1966 

Yes, I am stating that if your Gallery is based off a collection, it will never update - it is a snapshot of a table at a time.

I would set the Items property of the Gallery to:

ForAll('Test-Reviews' As _r,
    With({_vName:LookUp('Test-Vendors',ID=_r.VendorID, Title)},
        Patch(_r, {VendorName: _vName})
    )
)

Trying to ClearCollect again is just a performance waste in your app.  The Test-Reviews datasource is already populated with the new information.

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks - your logic makes perfect sense to me). To round it off I added the filter in there too...

ForAll(Filter('Test-Reviews',TripID=DrpTrips.Selected.ID) As _r,
    With({_vName:LookUp('Test-Vendors',ID=_r.VendorID, Title)},
        Patch(_r, {VendorName: _vName})
    )
)

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,552)