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 / ForAll Patch not working
Power Apps
Answered

ForAll Patch not working

(0) ShareShare
ReportReport
Posted on by 37

Hi,

 

I can see a lot of people are having trouble with the ForAll and Patch function working together, I am another one!

I have read many other posts, but I can't solve this one.

 

I have a Patch to change the status of a course; from 'Open' to 'Closed'. This works fine and only applies to one record. Then I want another Patch to change a different data source, but this one has many records to amend.

 

If it run it as normal Patch, it will only change the first record it sees, so ForAll is the solution (I think). But my formula for the ForAll shows errors.

 

Here is my formula:

 

ForAll.PNG

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,545 Most Valuable Professional on at

    One of the problems is that Lookup will only find the first record that matches.  I think instead what you want to do is a With() statement something like this.

    with({PatchRecords: Filter(PROP_Requests,'Course_ID' = galCourseOverview_1.Selected.Course_ID_Number)},
    forAll(PatchRecords,
     Patch(PatchRecords,thisRecord,{Course_Status: drpStatusUpdate.SelectedText.Value}))
  • ARV84Z Profile Picture
    37 on at

    Thank you for the quick reply.

     

    What is 'PatchRecords' referenced to? I couldn't see a formula called 'PatchRecords' , so assume I need to put something in there?

     

    To give you a little more context. The App is used to create training courses and log candidates attending them. The courses are logged in one data source (ODP_Courses_Lists), and are assigned a course ID number and status (open, full, complete). The candidates are logged in a separate data source (PROP_Requests), with the relevant course ID and status logged. When someone books onto a course, the course ID and status is logged against their name in PROP_Requests.

     

    But when I want to mark the course as complete, I need to do so on the course list data source, and for all candidates booked onto that course in PROP_Requests.

     

    I hope that makes sense. 

     

    Andy. 

  • Pstork1 Profile Picture
    69,545 Most Valuable Professional on at

    When you do a With() clause you can create a temporary value or set of records to be used in other expressions. PatchRecords is the name of a temporary records set that pre-filters the PROP_Requests collection/data source to select only the ones with the matching Course_ID. Then the ForAll() is applied to that subset of records to update the status.

  • ARV84Z Profile Picture
    37 on at

    Ok, that makes sense, thank you.

    I have tried the formula, but there is an error in the Patch formula:

    "The first argument of 'Patch' should be a collection"

    There is a red line under PatchRecords for the Patch source.

     

    Andy

  • Pstork1 Profile Picture
    69,545 Most Valuable Professional on at

    Sorry, one mistake in the Patch. You do the ForAll on PatchRecords, but the Patch should be on PROP_Requests

    with({PatchRecords: Filter(PROP_Requests,'Course_ID' = galCourseOverview_1.Selected.Course_ID_Number)},
    forAll(PatchRecords,
     Patch(PROP_Requests,thisRecord,{Course_Status: drpStatusUpdate.SelectedText.Value}))
  • ARV84Z Profile Picture
    37 on at

    It comes up with more errors when I do this.

     

    ForAll 2.PNG

     

    Error reasons:

    ForAll 1.PNG

  • Pstork1 Profile Picture
    69,545 Most Valuable Professional on at

    Check the name of the column you are trying to patch in the PROP_Requests list. The error says Course_Status doesn't exist.  What is the name of the Choice Column you are trying to patch?

  • ARV84Z Profile Picture
    37 on at

    Course_Status exists in PROP_Requests.

     

    Could it be that the filter in the With() formula might return a blank? As not all courses have names assigned to them in the PROP_Requests data.

  • Pstork1 Profile Picture
    69,545 Most Valuable Professional on at

    No, the error says the column can't be found.  Check the column settings and look at the URL. At the end will be the internal name of the column.  Verify that it matches what you are patching.

  • ARV84Z Profile Picture
    37 on at

    Hi, I can't seem to get this one working, sorry.

     

    ForAll 3.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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 481

#2
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#3
11manish Profile Picture

11manish 291

Last 30 days Overall leaderboard