Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

(0) ShareShare
ReportReport
Posted on by 4

Hi All, 

 

Need your help to my formula using ForAll and Patch functions. I have a form in my app connected to Sharepoint list named 'Tracker' and the I have a 'Worker_ID' Column connected to Column ID of 'Masterlist' list in Sharepoint , this Column was set as required and can select multiple. 

The idea is, if I selected one or multiple IDs, it will Patched in the Sharepoint list 'Tracker. 'I'm able to do both but the details are not accurate for multiple IDs.

 

If I selected multiple IDs, the details that my formula captures only the details of the last ID I've selected. Here's the formula I'm using. 

 

PABeginner26_4-1716451199741.png

 

Hope you could help me. Thank you!

 

Note: I store the IDs in a Collection named 'collID'.

  • DBO_DV Profile Picture
    4,642 Super User 2025 Season 1 on at
    Re: ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

    That will not be a problem with this formula but rather a problem with the formula where you collect the different ID's could you share the code Please?

     

    For the set problem this is the solution: 

    If(
    CountRows(collID) = 1,
    Patch(
     'Tracker',Defaults('Tracker'),
     {Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), Text(Int(rowCount)+1)), 'Requested For': LookUp('Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value, Title), 'Requested By':txtReqBy.Value, 'Workday ID': txtWorkdayID.Selected.Value, Item: txtItems.Selected, 'Request Type': txtReqType.Selected,'Specific Request Description':txtReqDesc.Value}
     ),
    CountRows(collID) > 1,
    Clear(rowCount);
    ForAll(
     collID,
     
    Patch(
    'Tracker',Defaults('Tracker'),{Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), rowCount), 'Requested By': txtReqBy.Value,'Requested For': LookUp('8982 HK Ops Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value,Title),'Workday ID': txtWorkdayID.Selected.Value,'Request Type':txtReqType.Selected, 'Specific Request Description': txtReqDesc.Value, Item: txtItems.Selected}
     );
    Collect(rowCount, {Value:CountRows(rowCount) + 1});
    )
    );

     

  • PABeginner26 Profile Picture
    4 on at
    Re: ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

    Got an error, Set is not working inside the ForAll function. But my problem is I'm not able to use the current data that the ForAll function processing.

    Sample I have selected 2 IDs (ID1, ID2) in the Workday ID control in my Canvas App, I'm not be able to use the first data the Workday ID control (ID1) and it only reads the last ID selected (ID2). So my current formula was patching 2 items in my Tracker sharepoint list with the same details (ID2).

     

    I want to Patch both IDs in the Sharepoint list. 

     

    Anyone can help me? 

  • DBO_DV Profile Picture
    4,642 Super User 2025 Season 1 on at
    Re: ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

    Hey Could you try this?

    If(
    CountRows(collID) = 1,
    Patch(
     'Tracker',Defaults('Tracker'),
     {Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), Text(Int(rowCount)+1)), 'Requested For': LookUp('Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value, Title), 'Requested By':txtReqBy.Value, 'Workday ID': txtWorkdayID.Selected.Value, Item: txtItems.Selected, 'Request Type': txtReqType.Selected,'Specific Request Description':txtReqDesc.Value}
     ),
    CountRows(collID) > 1,
    ForAll(
     collID,
     
    Patch(
    'Tracker',Defaults('Tracker'),{Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), rowCount), 'Requested By': txtReqBy.Value,'Requested For': LookUp('8982 HK Ops Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value,Title),'Workday ID': txtWorkdayID.Selected.Value,'Request Type':txtReqType.Selected, 'Specific Request Description': txtReqDesc.Value, Item: txtItems.Selected}
     );
    Set(rowCount, rowCount + 1);
    )
    );
  • PABeginner26 Profile Picture
    4 on at
    Re: ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

    Sure.

     

    Here it is. 

     

    If(
    CountRows(collID) = 1 And CountRows(collID) <> 0,
    Patch(
             'Tracker',Defaults('Tracker'),
              {Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), Text(Int(rowCount)+1)), 'Requested For':      LookUp('Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value, Title), 'Requested By':txtReqBy.Value, 'Workday ID': txtWorkdayID.Selected.Value, Item: txtItems.Selected, 'Request Type': txtReqType.Selected,'Specific Request Description':txtReqDesc.Value}
            ),
    if(
    CountRows(collID) >= 1,
    ForAll(
            collID,
        
    Patch(
    'Tracker',Defaults('Tracker'),{Title: Concatenate(Replace(strUniqueID,Find("[WDID]",strUniqueID),6,txtWorkdayID.Selected.Value), rowCount), 'Requested By': txtReqBy.Value,'Requested For': LookUp('8982 HK Ops Masterlist', 'Worker ID' = txtWorkdayID.Selected.Value,Title),'Workday ID': txtWorkdayID.Selected.Value,'Request Type':txtReqType.Selected, 'Specific Request Description': txtReqDesc.Value, Item: txtItems.Selected}
          );
    rowCount = rowCount + 1;
    )
      )
    );
  • DBO_DV Profile Picture
    4,642 Super User 2025 Season 1 on at
    Re: ForAll Patch all records from collection to Sharepoint List and use each record during loop to lookup values in another list

    Hey @PABeginner26 ,

     

    Could you please copy your code in here instead of a picture? This way we don't have to rewrite the whole thing.

    thanks!

     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 770 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 494

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 399