web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll Patch all recor...
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'.

Categories:
I have the same question (0)
  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    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!

     

  • PABeginner26 Profile Picture
    4 on at

    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;
    )
      )
    );
  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    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

    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? 

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    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});
    )
    );

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard