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 / Patch true/false works...
Power Apps
Answered

Patch true/false works, Forall Patch true/false does not.

(0) ShareShare
ReportReport
Posted on by 725

Hello to all

I have done a good amount of searching, but no luck.

The below works.

 

Patch(
 BSInspections,
 Defaults(BSInspections),
 {
 StationNum: {
 Id: NumT.ID,
 Value: NumT.StationNumber
 },
 BaitLeft: BLeft,
 BaitAdded: BAdded,
 Faeces: FaecesYN,
 InspectionDate: Today()
 }
)

 

But this next code does not patch the three yes no columns.

 

ForAll(
 ColStation,Patch(BSInspections,
 {StationNum:{Id:NumT.ID, Value:NumT.StationNumber},
 BaitLeft: BLeft,
 BaitAdded: BAdded,
 Faeces: FaecesYN,
 InspectionDate: Today()}
))

 

 I feel I am missing something very simple, thank you for your time.

Categories:
I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    I would explain it to you but @RandyHayes does it so much better

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @TheRobRush 

    Ah Yes!! 😉

     

    @Corissandageri 

    To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  It is a function that returns a table of records based on your iteration table and record schema.

    It is more efficient to use the function as intended and will provide better performance as the Patch function takes a datasource and a table (most performant syntax) to do its work.  And, ForAll supplies just that table!

     

    Patch(BSInspections,
     ForAll(ColStation,
     {StationNum: {Id:NumT.ID, Value:NumT.StationNumber},
     BaitLeft: BLeft,
     BaitAdded: BAdded,
     Faeces: FaecesYN,
     InspectionDate: Today()
     }
     )
    )

     

    But, you are using BLeft and BAdded and FaecesYN in your formula in both instances.  So it is obviously not a column in your collection ColStation...so what are those in your formula?

  • R Bakker Profile Picture
    725 on at

    Hi Randy

    I will make a note of that, I place a lot of value in app stability, however I have amended to your syntax and I am still getting the same result.

    My app, amongst other things has tree big buttons in a gallery which gets its values from a table. Note, The Name: part of the table is not currently being utilized.

    Table({LTitle:"Bait Left",Name:"Yes"}, {LTitle:"Bait Added",Name:"Yes"}, {LTitle:"Faeces",Name:"Yes"})

    Then I use them as on off buttons

    Switch(ThisItem.LTitle,"Bait Left",Set(BLeft,!BLeft),"Bait Added",Set(BAdded,!BAdded),"Faeces",Set(FaecesYN,!FaecesYN))

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Corissandageri 

    I would suggest using a checkbox in place of the button and variables.

    But, you are introducing a gallery now in your scenario.  So, I am not sure exactly what it is that you are trying to do overall.  You appear to be trying to set variables based on the value of LTitle when a button is pressed, but that would be global to everything, not specific to a record.  Also, if the condition is not met, then your variables will be blank until assigned a value.

     

    So...a little confused on the overall objective that you have. Perhaps you can expand and clarify.

  • R Bakker Profile Picture
    725 on at

    Well I got rid of my variables and swapped them with toggles but that didn't help

    ,the strange thing is the collection looks fine in the gallery and I am not getting any errors but it is not writing to Sharepoint correctly.

    Patch(BSInspections,
     ForAll(ColStation,{StationNum: {
     Id: NumT.ID,
     Value: NumT.StationNumber},
     
     BaitLeft: ToggleA.Value,
     BaitAdded: ToggleB.Value,
     Faeces: ToggleC.Value,
     InspectionDate: Today()
     }
     )
    )
  • Verified answer
    R Bakker Profile Picture
    725 on at

    Well as is often the case the answer was simple. ThisRecord

    ForAll(ColStation,
     Patch(BSInspections,
     {StationNum: {Id:NumT[@ID],
    Value:NumT[@StationNumber]},
     YNBaitLeft: ThisRecord.YNBaitLeft,BaitLeft:ThisRecord.BaitLeft,
     YNBaitAdded: ThisRecord.YNBaitAdded,BaitAdded:ThisRecord.BaitAdded,
     YNFaeces: ThisRecord.YNFaeces,Faeces:ThisRecord.Faeces,
     InspectionDate: Today()
     }
     )
    )
  • TheRobRush Profile Picture
    11,128 Moderator on at

    While it will work that way, it will do so inefficiently as your forall is on the outside of the patch, instead of inside it, which means instead of running patch once, its running it however many times x number of items you have. As long as that works for you, it's fine. But If you hit large datasets it's not going to be the best for performance.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Corissandageri 

    So if you're still concerned over performance and stability, you will want to use the ForAll properly.

    Your formula should be the following:

    Patch(BSInspections,
     ForAll(ColStation,
     {StationNum: {Id:ID, Value:StationNumber},
     YNBaitLeft: YNBaitLeft,
     BaitLeft: BaitLeft,
     YNBaitAdded: YNBaitAdded,
     BaitAdded: BaitAdded,
     YNFaeces: YNFaeces,
     Faeces: Faeces,
     InspectionDate: Today()
     }
     )
    )

     

    The reason you were having issues before with the toggles (which is still the preferred method) is that you were not addressing the toggles in the context of the Gallery, but outside of it.  So it would have only referenced the first record toggle values.  This is because you are using a collection which is a duplicate of your gallery data.  Your formula should be based off of the gallery, not a collection, as that is what holds the information that you need.

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 393

#2
WarrenBelz Profile Picture

WarrenBelz 345 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 271 Super User 2025 Season 2

Last 30 days Overall leaderboard