Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Patch Multiple Records Using For all and a Filter

(0) ShareShare
ReportReport
Posted on by 17

Hi,

 

I am creating an app that lists tasks of 2 types of shutdown. I am using Patch to update each record as they are completed.  What I am trying to do now is essentially 'reset' the sharepoint list for each type of shutdown so that it can be used for the next shutdown.

I am trying to filter the list by shutdown type then patch the Completed column and Task Completed column so that they say false.

So I am filtering a data source by one column, then patching all the records that the filter returns.

 

This is what I have so far...

 

ForAll('Pilot TC San', (Patch('Pilot TC San',LookUp('Pilot TC San',Shutdown=Dropdown1.Selected.Result),{Completed:false,TaskComplete:False})))

 

Dropdown.Selected.Result is the type of shutdown that is to be reset.

 

I get an error which states 'This Function cannot operate on the same data source that is used in the ForAll function'.

 

Any help on this would be much appreciated

  • AllyCrop Profile Picture
    AllyCrop 17 on at
    Re: Patch Multiple Records Using For all and a Filter

    The UpdateIf worked a treat, thank you. It wasn't a function I was aware of, so I was overcomplicating it by using functions I knew about.

  • Verified answer
    v-xida-msft Profile Picture
    v-xida-msft on at
    Re: Patch Multiple Records Using For all and a Filter

    Hi @AllyCrop ,

    Could you please share a bit more about your scenario?

    Do you want to update the Completed column and Task Completed column of all related records in your data source based on the shutdown type specified within the Dropdown1?

     

    Based on the error message that you mentioned, I think there is something wrong with your formula. You could not specify same data source within the Patch function as that within your ForAll function. I assume that you used a Gallery control in your app to list all records from your SP List, and you connect the Gallery to your 'Pilot TC San' List data source, is it right?

    Please modify your formula as below:

    ForAll(
     Gallery1.AllItems, 
     Patch(
     'Pilot TC San',
     LookUp('Pilot TC San',Shutdown = Dropdown1.Selected.Result),
     { 
     Completed: false,
     TaskComplete: false
     }
     )
    )

     

    Actually, I think it is not necessary to use ForAll function to achieve our needs, instead, I think the UpdateIf function is enough. Please consider take a try with the following formula:

    UpdateIf(
     'Pilot TC San',
     Shutdown = Dropdown1.Selected.Result,
     {
     Completed: false,
     TaskComplete: false
     }
    )

     

    Please take a try with above solution, check if the issue is solved.

     

    Best regards,

  • eka24 Profile Picture
    eka24 20,921 on at
    Re: Patch Multiple Records Using For all and a Filter

    If the filtering is done in a Gallery or  a Collection, the Use the Gallery or Collection name ForAll instead of the table name:


    ForAll(CollectionName, (Patch('Pilot TC San',LookUp('Pilot TC San',Shutdown=Dropdown1.Selected.Result),{Completed:false,TaskComplete:False})))

     

     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,445

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,741

Leaderboard