cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
romber
Helper II
Helper II

Current record inside the ForAll function

Hi, I would like to ask you something,

 

My question is more general. How to work with the current record which is processing in the ForAll loop. I'm quite stuck with that.

 

for better imagination lets assume that I have ForAll function in that function I need to let's say patch record. I need id of the current record in the for all function to use it in the patch function.

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@romber 

Sure we can do an example together 🙂

 

In the example our goal is to update several records currently having a Status of "Open" to the Status "Closed".  We already have the ID of all records we want to update stored in a Collection called myRecords.  See my sample code below.

 

ClearCollect(
    myRecords,
    {ID:1001},{ID:1201},{ID:1315},{ID:1467},{ID:1500}
);

 

To perform the patch we can use use this code.  Do you notice how I have referenced the current ID being looped over by writing myRecords[@ID].  This technique is called disambiguation.  The column ID exists in both myRecords and mySharePointList so we  must tell PowerApps to look at myRecords using the square brackets otherwise it will just look at the ID column for the current scope of LOOKUP which is mySharePointList. 

 

ForAll(
    myRecords,
    Patch(
        mySharePointList,
        LookUp(mySharePointList, ID: myRecords[@ID]),
        {Status: "Closed"}
);

 

Let me know if you have any further questions.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

2 REPLIES 2
mdevaney
Super User
Super User

@romber 

Sure we can do an example together 🙂

 

In the example our goal is to update several records currently having a Status of "Open" to the Status "Closed".  We already have the ID of all records we want to update stored in a Collection called myRecords.  See my sample code below.

 

ClearCollect(
    myRecords,
    {ID:1001},{ID:1201},{ID:1315},{ID:1467},{ID:1500}
);

 

To perform the patch we can use use this code.  Do you notice how I have referenced the current ID being looped over by writing myRecords[@ID].  This technique is called disambiguation.  The column ID exists in both myRecords and mySharePointList so we  must tell PowerApps to look at myRecords using the square brackets otherwise it will just look at the ID column for the current scope of LOOKUP which is mySharePointList. 

 

ForAll(
    myRecords,
    Patch(
        mySharePointList,
        LookUp(mySharePointList, ID: myRecords[@ID]),
        {Status: "Closed"}
);

 

Let me know if you have any further questions.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney Very helpful 🙌  thanks!!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,631)