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 / Reference Current Reco...
Power Apps
Answered

Reference Current Record of ForAll

(1) ShareShare
ReportReport
Posted on by 15

I'm trying to use ForAll() to loop through a Gallery and update an "Approval Status" column based on the value from a Toggle (Toggle1). This is what I currently have:

 

ForAll(
 Gallery2.AllItems
 ,
If(
 Toggle1.Value,
 Patch('[dbo].[LINEITEM]', First(Filter('[dbo].[LINEITEM]',ID=ID)), {APPROVAL_STATUS: "Approved"}), 
 Patch('[dbo].[LINEITEM]', First(Filter('[dbo].[LINEITEM]',ID=ID)), {APPROVAL_STATUS: "Rejected "})
 ))

But when I push the button to run this code, the toggles are all switching back to `true`. This is dicated by the following Default Code: 

 

If(ThisItem.APPROVAL_STATUS="Approved", true, false)

It seems that the `ID=ID` piece is what isn't working properly. What am I missing to make this work properly? 

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @12vanblart,

    If you try ID=ThisItem.ID does it work?

  • 12vanblart Profile Picture
    15 on at

    When I try this, It doesn't recognize `ThisItem` as valid. 

     

    Error: 

     

    Name isn't valid. This identifier isn't recognized. This error appears most commonly when a formula refers to something that no longer exists (for example, a control that you've deleted).
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @12vanblart,

     

    Ok, please try ForAll( Gallery2.AllItems, UpdateIf('[dbo].[LINEITEM]', Toggle1.Value, {APPROVAL_STATUS: "Approved"},!Toggle1.Value,{APPROVAL_STATUS: "Rejected "})).  Let me know if that works.

  • 12vanblart Profile Picture
    15 on at

    @Drrickryp,

     

    This resolved the error message, but it doesn't seem to be setting correctly. i.e. I have a set of 3 items to loop over and I set the toggles to a status of {False, True, False}. Then after running the code their status is {False, False, False}. 

     

    I've run a couple of setups and it looks like it's only checking against the last toggle item.

     

    i.e.)

    {False, False, True} => {True, True, True}

    {True, True, False} => {False, False, False}

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

    Hi @12vanblart,

    Do you display the Approval Status column value using Toggle control within your app?

     

    I think there is something wrong with the formula that you provided. I have made a test on my side (use a SP list as the data source of my app), please take a try with the following workaround:

    The data structure of SP list as below:5.JPG

    App's configuration as below:

    6.JPG

     

    7.JPG

    Set the OnSelect property of the "Submit" button to following formula:

    ForAll(
    RenameColumns(Gallery1.AllItems,"ID","ID1"),
    If(
    Toggle1.Value=true,
    Patch('20181002_case6',LookUp('20181002_case6',ID=ID1),{ApprovalStatus:"Approved"}),
    Patch('20181002_case6',LookUp('20181002_case6',ID=ID1),{ApprovalStatus:"Rejected"})
    )
    )

    On your side, you should type the following formula:

    ForAll(
    RenameColumns(Gallery1.AllItems,"ID","ID1"),
    If(
    Toggle1.Value=true,
    Patch('[dbo].[LINEITEM]',LookUp('[dbo].[LINEITEM]',ID=ID1),{APPROVAL_STATUS:"Approved"}),
    Patch('[dbo].[LINEITEM]',LookUp('[dbo].[LINEITEM]',ID=ID1),{APPROVAL_STATUS:"Rejected"})
    )
    )

     

    Or

    ForAll(
    RenameColumns(Gallery1.AllItems,"ID","ID1"),
    If(
    Toggle1.Value=true,
    Patch('[dbo].[LINEITEM]',First(Filter('[dbo].[LINEITEM]',ID=ID1)),{APPROVAL_STATUS:"Approved"}),
    Patch('[dbo].[LINEITEM]',First(Filter('[dbo].[LINEITEM]',ID=ID1)),{APPROVAL_STATUS:"Rejected"})
    )
    )

    The GIF screenshot as below:Test1.gif

     

     

    More details about the Patch function and RenameColumns function in PowerApps, please check the following workaround:

    Patch function, RenameColumns function

     

    In addition, you could also consider take a try to set the OnChange property of the Toggle control (within the Gallery control) to following formula:

    If(
    Toggle1.Value=true,
    Patch('[dbo].[LINEITEM]',ThisItem,{APPROVAL_STATUS:"Approved"}),
    Patch('[dbo].[LINEITEM]',ThisItem,{APPROVAL_STATUS:"Rejected"})
    )

     

    Best regards,

    Kris

     

  • 12vanblart Profile Picture
    15 on at

    @v-xida-msft,

     

    Thank you so much! This is working as expected now! It looks like the Rename Columns function is what was missing to make it all work! 

     

    As for the OnChange property for the toggles themselves, I initially had it setup like this, but if you tried to toggle another item before the Patch was handled, it would undo the items toggled between first item toggled and Patch completing (idk if that sentence makes much sense?) 

     

    Thanks again for your assistance! 

  • 12vanblart Profile Picture
    15 on at

    @v-xida-msft

     

    After working on the app some more, everything is working in the Edit Environment, but when I try to navigate to the page with the toggles in the published version of the App, I'm getting this error: 

    Capture.PNG

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 610

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard