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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patching all gallery i...
Power Apps
Answered

Patching all gallery items

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi!  I'm a bit stuck with some code, any help will be hugely appreciated 🙂

 

What I'm trying to achieve:  First, check a selection of records, and send an email just to them.

 

Screen 1:  Check boxes next to the main gallery records, on checking them it updates the data 'SendEmail' column for that record from "N" to "Y" to indicated that this person needs an email sending to them.

 

Screen 2: Gallery displays just the items with 'SendEmail' as "Y" (to allow the user to double check the distribution list)

 

On Screen 2, Send Email Button at the bottom which should:

First, Send the email to all in "Y" people <-- This part works

Then, patch all these records back to being "N" ready for next time to reset the Screen 2 gallery back to being empty <-- this is the part I'm struggling with.

 

Current button code - green parts work, red part doesn't:

 

ForAll(BrowseGallery1_5.AllItems,Office365Outlook.SendEmailV2(Email, DataCardValue27,DataCardValue35));Patch(BrowseGallery1_5.AllItems, {SendEmail: "N"});Navigate('Emails Successful')

 

Any help will be hugely appreciated 🙂

 

Thank you!

Categories:
I have the same question (0)
  • eka24 Profile Picture
    20,925 on at

    Try

    ForAll(BrowseGallery1_5.AllItems,Office365Outlook.SendEmailV2(Email, DataCardValue27,DataCardValue35));

    ForAll( BrowseGallery1_5.AllItems),

    Patch(Datasource, Defaults (Datasource),

    {SendEmail: "N"});Navigate('Emails Successful')

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi, 

    Thanks for your help!

    It's still sending out email and navigating, but not completing the patch back to "N".  

    It's giving out an error:  Title: The field Title is required.

    Title is the only mandatory field in the sharepoint list, (I think sharepoint lists have to have one mandatory column by the looks of it), and Title is that column - I think it has something to do with the use of Defaults maybe?

     

    Thanks again 🙂

     

  • eka24 Profile Picture
    20,925 on at

    Are you updating the field or inserting new row with N.

    Also if the title is required then it must be included in the patch or else remove the required in the list

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for getting back to me!

     

    Datasource looks like this:

     

    Title*First NameLast NamePhoneEmailSendEmail
    MrJohnSmith01112223334john.smith@....N
    MrsJaneSmith055556667778jane.smith@....N
    MsJoeSmith088889990001joe.smith@....N

     

    Title has to be required as the Sharepoint List requires it, I'm pretty new to sharepoint lists but I can't see an option to change that for this column (every other column has the option, but not this one).

     

    In the app, Screen One, is a gallery view of all the records in the datasource, each record has a checkbox by it so the user can choose who to email.

     

    The user would (for example) check the checkbox next to John & Joe in the gallery to email them, this patches SendEmail to "Y"

     

    Title*First NameLast NamePhoneEmailSendEmail
    MrJohnSmith01112223334john.smith@....Y
    MrsJaneSmith055556667778jane.smith@....N
    MsJoeSmith088889990001joe.smith@....Y

     

    Gallery in Screen Two has a filter on so displays just John & Joe so that the user can confirm that it's just these two that they're emailing.

     

    Send button at the bottom sends the email to all in this gallery, and then (should) patch the "Y"s back to "N", to reset everything ready for the next time they want to send out the email.  At the moment the email gets sent, but the records stay set to "Y" instead of patching back to "N".

     

    Hope that helps 🙂

  • Verified answer
    v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous :

    Firstly, Let me explain why this code do not work.( Patch(BrowseGallery1_5.AllItems, {SendEmail: "N"}))

    The point is BrowseGallery1_5.AllItems does not point to your data source.

    The Patch function cannot find your data source, so it cannot update the data.

    I suggest you try this code:

    ForAll(
     RenameColumns(
     Filter(
     GalleryDataSource, /*you datasource*/
     SendEmail =”Y” && ID in BrowseGallery1_5.AllItems.ID
     ),
     "ID", /* ID is the standard field of SharePoint list and can be directly cited */
     "DD" /* Modify the field name of the temporary table to prevent ambiguity */
     ), 
     Patch(
     GalleryDataSource, /*you datasource*/
     LookUp(
     GalleryDataSource, /*you datasource*/
     DD = ID
     ),
     { SendEmail: "N"}
     )
    )

    Secondly, I think it is more convenient to use the UpdateIf function.

    UpdateIf(GalleryDataSource/*you datasource*/, SendEmail =”Y” && ID in BrowseGallery1_5.AllItems.ID ,{ SendEmail:”N”})
    /* ID is the standard field of SharePoint list and can be directly cited */

    I think this link will help you a lot:

    Update and UpdateIf functions in Power Apps

    Best Regards,

    Bof

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 494

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
11manish Profile Picture

11manish 323

Last 30 days Overall leaderboard