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 / Delegation issue insid...
Power Apps
Answered

Delegation issue inside of a ForAll -- Patch code block

(0) ShareShare
ReportReport
Posted on by 23

Hi all,

I have with an update operation with two SharePoint Lists. The first List 'SiteGroups' is the master table and each time there is a change in this table, there have to be created a record in the second table 'ActionQueue'. The table ActionQueue acts as queue for further processess. As long as an action is not completed the record in SiteGroups is locked against further changes. 

 

When the user changes a record in the SiteGroups and doesn't stop the running PowerApp session , the code will create the required entry in the ActionQueue table. But when the PowerApp session terminats before, there could be changes in SiteGroups, without an corresponding entry in ActionQueue.

 

The intention of the following code block  is to fix this issue

 

ClearCollect(

colCheckSiteGroups;
Filter(SiteGroups; paProcessStatus = "waiting"; ActionID = 0)
);

ForAll(

colCheckSiteGroups;
Patch(SiteGroups;

LookUp(SiteGroups; ID = colCheckSiteGroups[@ID]);
{ActionID:

Patch(ActionQueue;

Defaults(ActionQueue);
{

PendingAction: colCheckSiteGroups[@PendingAction];
ActionForListID: colCheckSiteGroups[@ID]

}

).ID

}

)

)

 

Unfortunatly the PowerApp studio comes up with a delegation warning, which a highlighted in blue. With a small amount of records it works fine, but not with a larger amount, which have to be expected. I tried to  populate the colCheckSiteGroups; collection with a FirstN statement, but that doesn't help.

Could you please give me a suggestion how to fix this issue?

 

Kind regards 

Chris

Categories:
I have the same question (0)
  • Verified answer
    iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Hi @Chris10 

     

    Could you try using the following:

     

    ClearCollect(
     colCheckSiteGroups;
     Filter(SiteGroups; paProcessStatus = "waiting"; ActionID = 0)
    );
    
    ForAll(
     colCheckSiteGroups;
     With(
     {currentID: colCheckSiteGroups[@ID]},
     
     Patch(
     SiteGroups;
    
     LookUp(SiteGroups; ID = currentID);
     {
     ActionID:
    
     Patch(
     ActionQueue;
     Defaults(ActionQueue);
     {
    
     PendingAction: colCheckSiteGroups[@PendingAction];
     ActionForListID: currentID
     }
     ).ID
     }
     )
     )
    )

     

    I've seen recently from a fellow Power Apps Guru, @wyotim that using With circumvents the particular issue with delegation that you are facing, so if you could try the above and let me know if it resolves your issue?

     

    (Tim if I made a mistake implementing your method I'd be super appreciative if you corrected it! 😺 )

     

    Cheers,

    Sancho

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Chris10 ,

    How many records stored in your SiteGroups List? More than 2000?

     

    Currently, the Disambiguation operator ([@]) could not be delegated in Filter or LookUp function. If the records stored in your SiteGroups List is not more than 2000, you could ignore this Delegation warning issue.

     

    As an fixed solution, I agree with @iAm_ManCat 's thought almost. I think the With function could achieve your needs. I have made a test on my side, the screenshot as below:

    7.JPG

    Modify your ForAll function as below:

    ForAll(
     colCheckSiteGroups;
     With(
     {
     LoopItemID: colCheckSiteGroups[@ID],
     LoopPendingAction: colCheckSiteGroups[@PendingAction]
     },
     Patch(
     SiteGroups;
     LookUp(SiteGroups; ID = LoopItemID);
     {
     ActionID: Patch(
     ActionQueue;
     Defaults(ActionQueue);
     {
     PendingAction: LoopPendingAction;
     ActionForListID: LoopItemID
     }
    
     ).ID
     }
     )
     )
    )

     

    But there still have an limit with the ForAll function -- The ForAll function is not a Delegable function, so it could only process first 2000 records at most from your colCheckSiteGroups collection. If the amount of records in your colCheckSiteGroups collection is more than 2000, the ForAll function would not work for your scenario.

     

    Best regards,

  • Chris10 Profile Picture
    23 on at

    Thanks a lot for your advice. For the moment I wouldn't expect more than 2000 items. But what if there are more than 2000 items?  I thougth one approach could be to implement the code block inside of a timer event and restart the timer as long as the final condition find more failed transactions. 

    Do you have any recommendation?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,045

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 592

Last 30 days Overall leaderboard