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 / Using ForAll function ...
Power Apps
Answered

Using ForAll function Patch Multiple SharePoint list items

(0) ShareShare
ReportReport
Posted on by 27

Hi All,

 

I have a SharePoint list which looks like below:

IDSourceDestinationStartDateEndDateEntryDateLeaveDate
1SRC1DES101/02/202201/02/202201/02/202206/02/2022
2SRC2DES206/02/202206/02/202206/02/202206/02/2022
3SRC3DES304/02/202204/02/202204/02/2022 

 

Expected Result:

IDSourceDestinationStartDateEndDateEntryDateLeaveDate
1SRC1DES101/02/202201/02/202201/02/202204/02/2022
3SRC3DES304/02/202204/02/202204/02/202206/02/2022
2SRC2DES206/02/202206/02/202206/02/202206/02/2022

 

How can I achieve the above expected result on a click of a button?

 

Any help would be greatly appreciated. Thank you in advance.

@RandyHayes 

@RezaDorrani 

Categories:
  • Gochix Profile Picture
    1,937 Moderator on at

    Hi @AshwiniGBS ,

     

    Basic ForAll patch :

     

     

    ClearCollect(
     tempCol,
     'YourDataSource'
    );
    
    ForAll(
     tempCol As aRecord,
     If(!IsBlank(LookUp('YourDataSource',ID = aRecord.ID),
     Patch('YourDataSource',Defaults('YourDataSource'),
     {
     StartDate: ..., // change the columns and values what to patch.
     EndDate: ...
     }
     )
     )
     )

     

     


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • AshwiniGBS Profile Picture
    27 on at

    Thank you @Gochix for the reply.

     

    This is one part of my solution.

    AshwiniGBS_0-1661785489773.png

    Above is an example to show how I am updating in my actual DataSource.

     

    Please see in my original post the Expected Result for the second part of the solution I am looking for:

    is to select N+1 and retrieve its StartDate and update LeaveDate for N (where N is the SharePoint ID).

     

    Thanks

     

  • Verified answer
    Gochix Profile Picture
    1,937 Moderator on at

    This then would be probably something like:

     

    ClearCollect(
     tempCollection,
     DTAdmins
    );
    ForAll(
     tempCollection As _item,
     With(
     {
     _Lookup: LookUp(
     DTAdmins,
     ID = _item.ID
     ),
     _UpdateLeaveDate: LookUp(DTAdmins,
     ID = _item.ID + 1
     )
     },
     If(
     !IsBlank(_Lookup),
     Patch(
     DTAdmins,
     _Lookup,
     {
     Created:_Lookup.Created,
     LeaveDate: _UpdateLeaveDate.StartDate
     }
     )
     )
     )
    )

     


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

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

    @AshwiniGBS 

    First, you'll want to use the ForAll properly - not as a For Loop as this will kill your performance, and it is not how it was designed.

    No collections are needed for this, but what is the logic for what you want in the LeaveDate?

     

  • AshwiniGBS Profile Picture
    27 on at

    My scenario is something as below:

    This is a Transportation list where user can enter their journey details randomly. So, these are the steps that I followed to update the entries for my future calculations: (For now on a click of a button)

    - ClearCollect the transportation list with Unique ID and Sort in ascending on StartDate of the journey's.

    - Created an Index column in the same collection which gives me a sequence of the items. 

    - Next in the ForAll I perform all the calculations that I need. Basically, modify the LeaveDate for N+1 and change StartDate for item N. 

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard