cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate IV
Advocate IV

Filtering a collection

Hi

 

I have a GalleryDetails with text input controls for creating new records.

  1. When I enter a few records in this gallery, I click the save button and this data gets saved into a collection
  2. Then I click another save button to write it to the Common Data Service with the patch function.

This works great for creating new records but now I want to edit those records in that same GalleryDetails based on a record that I select in another Gallery thats named GalleryMaster

 

So I've created an edit button with this code to:

  1. get the records back from the Common Data Service Entity "CDSDetails"
  2. put those records in the CollectionDetails
  3. And show them in my GalleryDetails so I can edit them

This is the edit button OnSelect to create the above magic:

Collect(
    CollectionDetails;
    Filter(
        CDSDetails;
        MasterID = GalleryMaster.Selected.ID
    )
)

But unfortunately this formula doesn't work. I admit I don't yet fully understand collections. Maybe the formula is correct but "MasterID" isn't. This field is a lookupfield as it represents a relationship between CDSMaster and CDSDetails in the common data service and for some reason it's dotted in blue as a warning for delegation, but even then it just doesn't work as I'm below 500 records at this moment and the button doesn't work at all...

If I change MasterID to ID the formula works but the information that is shown in the GalleryDetails is not correct at all as it shows a blank gallery...

 

Any help is much appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advocate IV
Advocate IV

Re: Filtering a collection

Thank you! I watched some videos of Shane and this was very helpful! Funny guy 🙂 For the above problem I eventually used:

 

Clear(CollectionDetails);;

ForAll(
    GalleryMaster.Selected.CDSDetails;
    Patch(
        CollectionDetails;
        Defaults(CollectionDetails);
             ...

GalleryMaster.Selected.CDSDetails passes the ID to the CDSDetails Entity. Changing this part with a Filter-function didn't work... very strange...I probably still don't understand how to pass an ID that is selected in a gallery to the many side of a relationship in CDS with a filter-function without delegation issues.

View solution in original post

4 REPLIES 4
Highlighted
Super User
Super User

Re: Filtering a collection

Hi @svenvu 

It appears to me that your app is unnecessarily complicated because you are trying to use galleries for data input.  In general, galleries are used to display data (think of it as a report) and forms are used for creating new records and editing existing records.  In relational databases, you will use galleries to select a subset of records to edit, for example, customers and orders.  In that case you would use 2 galleries and 2 edit forms, one for the details of the customer and one for the details of the order.  For an example, please check my post in the Community Blog Relational-Database-Design-fundamentals-Implementing-a-One-to-many relationship in PowerApps

Highlighted
Advocate IV
Advocate IV

Re: Filtering a collection

Hi @Drrickryp 

 

Thank you for the link. I found it very useful, especially the "ID" parts, as I still need to learn a lot!

I understand the basic concept of galleries vs forms but unfortunately forms only allow editting one item and that isn't very userfriendly for heavy data input when users need to enter many items. In my case: create a masterItem and immediately create 4 subitems with 6 columns. I don't see any other userfriendly way of creating such a solution.

 

I can use the form for creating the masteritem but then I must use a gallery with 4 rows of 6 inputcontrols as a kind of editable table. The benefit of a gallery is that I only need to create 6 inputcontrols that are automatically created in the 3 rows below = total of 4 galleryitems. This gallery is set by a collection of 4 rows so the gallery shows 4 items that the user can fill in. The filled in inputboxes needs to be saved back to the collection and then saved to the real CDS-datasource.

 

I found some info on ForAll with a Patch-function and try that later instead of Collect.

Highlighted
Super User
Super User

Re: Filtering a collection

Hi  @svenvu 

If you want to see some extremely clever uses of galleries for data input, check out @Shanescows  videos nfopath+form+powerapps.  I believe that you will get some great ideas from this as to how to present your app to your users.  Infopath was one of the precursors to Powerapps that was deprecated by Microsoft but it still had dedicated users who needed to transition.  What you want to do is not an out of the box solution in PowerApps but others have blazed that trail for you.  See what you think.  Shane has many videos that are extremely practical and were my guide to learning PowerApps. 

Highlighted
Advocate IV
Advocate IV

Re: Filtering a collection

Thank you! I watched some videos of Shane and this was very helpful! Funny guy 🙂 For the above problem I eventually used:

 

Clear(CollectionDetails);;

ForAll(
    GalleryMaster.Selected.CDSDetails;
    Patch(
        CollectionDetails;
        Defaults(CollectionDetails);
             ...

GalleryMaster.Selected.CDSDetails passes the ID to the CDSDetails Entity. Changing this part with a Filter-function didn't work... very strange...I probably still don't understand how to pass an ID that is selected in a gallery to the many side of a relationship in CDS with a filter-function without delegation issues.

View solution in original post

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (7,321)