cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jbjb247
Helper II
Helper II

Patching all gallery items

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!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @jbjb247 :

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

View solution in original post

5 REPLIES 5
eka24
Super User
Super User

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.

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 🙂

 

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

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 🙂

Hi @jbjb247 :

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

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (865)