cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
12vanblart
Level: Powered On

Reference Current Record of ForAll

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Reference Current Record of ForAll

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

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Super User
Super User

Re: Reference Current Record of ForAll

Hi @12vanblart,

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

12vanblart
Level: Powered On

Re: Reference Current Record of ForAll

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).
Super User
Super User

Re: Reference Current Record of ForAll

@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
Level: Powered On

Re: Reference Current Record of ForAll

@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}

Community Support Team
Community Support Team

Re: Reference Current Record of ForAll

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

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

12vanblart
Level: Powered On

Re: Reference Current Record of ForAll

@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
Level: Powered On

Re: Reference Current Record of ForAll

@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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,759)