web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll and ClearCollec...
Power Apps
Unanswered

ForAll and ClearCollect to send gallery items to SharePoint List?

(0) ShareShare
ReportReport
Posted on by 271

I'm working on a proof of concept app that allows a user to manually update the location of team members (or those they supervise). The app pulls data from a "master personnel list" which assigns individuals to a "reporting" party. When screen is OnVisible, those individuals are automatically added to a collection, and that collection is then displayed in a gallery. I've added two elements to the gallery card: a location drop-down menu, and a Notes text entry field. My objective is to be able to select a location from the drop-down menu and enter notes for each person, and upon submit each person is added as an item to a different SharePoint list ('Personnel Check-ins').

 

MarcusD1_0-1709657015362.png

 

I believe the solution involves the ForAll() function; but I'm struggling to figure out how to make it work.

 

I thought it might look something like this, but it clearly isn't correct:

ClearCollect(
 coll_CadreStatus,
 ForAll(
 gal_TeamLocations.AllItems,
 lbl_TeamMemberTitle.Text,
 dd_CadreLoc.SelectedText.Value,
 txt_CadreLocNotes.Text
 ));
Collect(
 'Personnel Check-ins',
 coll_CadreStatus
)

 

Any tips on how to make this work?

Categories:
I have the same question (0)
  • realwillwright Profile Picture
    772 Moderator on at

    Hi @MarcusD1 

     

    There are several ways to do this as written about in this blog by Craig White Patch Multiple Rows In Power Apps Like A Jedi! - Platforms of Power

     

    For your situation as I don't know all the ins and outs I will show you the ForAll method. There may be some tweaks needed.

     

    ForAll(gal_TeamLocations.AllItems,
     Patch(
     'Personnel Check-ins',
     Defaults('Personnel Check-ins'),
     {
     Name: TeamMemberTitle.Text,
     Location: dd_CadreLoc.Selected.Value,
     Notes: txt_CadreLocNotes.Text,
     }
     )
    );

     

    -------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Verified answer
    CarlosFigueira Profile Picture
    on at

    You shouldn't need a collection for that, you can "cache" the gallery items using the With function with an expression similar to the one below:

    With(
     { itemsToAdd: galTeamLocations.AllItems },
     Patch(
     'Personnel Check-ins',
     Defaults('Personnel Check-ins'),
     {
     Title: lblTeamMemberTitle.Text,
     Location: dd_CadreLoc.SelectedText.Value,
     Notes: txt_CadreLocNotes.Text
     }
     )
    )

    If you do want to use a collection (may help with debugging), you need to update your ForAll expression to store the data extracted from the gallery as a record:

    ClearCollect(
     coll_CadreStatus,
     ForAll(
     gal_TeamLocations.AllItems,
     {
     Title: lbl_TeamMemberTitle.Text,
     Location: dd_CadreLoc.SelectedText.Value,
     Notes: txt_CadreLocNotes.Text
     }
     )
    );
    Collect(
     'Personnel Check-ins',
     coll_CadreStatus
    )

    Note that I used the column names 'Title', 'Location' and 'Notes', but you would have to use the names from your SharePoint list.

    Hope this helps!

  • MarcusD1 Profile Picture
    271 on at

    Thanks @realwillwright - I tired your approach, but it kept telling me the Patch function had invalid arguments. Couldn't figure out where the issue was. But the reference link you provided is helpful. I'll definitely give that a look and see if it provides the insight to make the necessary adjustment for that strategy to work.

  • MarcusD1 Profile Picture
    271 on at

    Thank you @CarlosFigueira - your second option with the Collection worked great, after I changed the Location drop-down data type given it's a choice column in the SP list. This is the final code:

    ClearCollect(
     coll_CadreStatus,
     ForAll(
     gal_TeamLocations.AllItems,
     {
     Title: lbl_TeamMemberTitle.Text,
     Location: dd_CadreLoc.Selected,
     LocNotes: txt_CadreLocNotes.Text
     }
     )
    );
    Collect(
     'Personnel Check-ins', coll_CadreStatus
    )

     

    I did try the first strategy you offered, but it only added the last item in my gallery list to the SP list (vs. all three)? Any idea why that might be?

  • MarcusD1 Profile Picture
    271 on at

    @CarlosFigueira ...annnnnddd one more question. After getting the initial function to work, I tried adding what I thought would be a simple additional element: the profile name of the person submitting the data. The destination column is a "Person" column (i.e. Outlook profile lookup) in the SP list.

     

    ClearCollect(
     coll_CadreStatus,
     ForAll(
     gal_TeamLocations.AllItems,
     {
     Title: lbl_TeamMemberTitle.Text,
     CheckinDateTime: Now(),
     Location: dd_CadreLoc.Selected,
     LocNotes: txt_CadreLocNotes.Text,
     AcntblyReporter: Office365Users.MyProfileV2().displayName
     }
     )
    );
    Collect(
     'Personnel Check-ins', coll_CadreStatus
    )

     

    The problem is I get an error: "Incompaticable type. The 'AnctblyReporter' column in the data source you're updating expects a 'Record' type and you're using a 'Text' type. I tried removing the '.displayName' - and that allowed the push, but my name wasn't actually recorded in that column. I also tried AcntblyReporter: {Value:Office365Users.MyProfileV2().displayName}, and that also allowed the push, but still didn't add my name to the AcntblyReporter column in the SP list.

     

    When I check the collection in the app after a push, it shows a "Record" is created in the collection for that column:

    MarcusD1_0-1709669500018.png

     

    How can I get my profile display name to successfully push to the SP column?

  • Verified answer
    CarlosFigueira Profile Picture
    on at

     

     

    The Person column in SharePoint needs to be passed as a record. I remembered that it required a Claims field, with a value similar to <<"i:0#.f|membership|" & <principalName> >>, so I started trying to add it to a SP list that I created here, and it kept complaining about missing fields in that record, until I got them all. This worked for me, give it a try to see if this works for you as well.

     

    With(
     { me: me:Office365Users.MyProfileV2() },
     ClearCollect(
     coll_CadreStatus,
     ForAll(
     gal_TeamLocations.AllItems,
     {
     Title: lbl_TeamMemberTitle.Text,
     CheckinDateTime: Now(),
     Location: dd_CadreLoc.Selected,
     LocNotes: txt_CadreLocNotes.Text,
     AcntblyReporter: {
     Claims: "i:0#.f|membership|" & me.userPrincipalName,
     Department: me.department,
     DisplayName: me.displayName,
     Email: me.mail,
     JobTitle: me.jobTitle,
     Picture: Blank()
     }
     }
     )
     )
    );
    Collect(
     'Personnel Check-ins', coll_CadreStatus
    )

     

    If this doesn't work, try to see the format that the Claims field use in our list, by adding a label and setting its Text property to First('Personnel Check-ins').AcntblyReporter.Claims.

    Hope this helps!

  • MarcusD1 Profile Picture
    271 on at

    That did the trick! Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard