cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
PhilD
Level 8

Update field if other field matches - delegation limit

Using SharePoint list as DataSource. To find those records where Area="Area 1" and change them all to be "Area 2", the code below works fine except that it is subject to the delegation limitation in the ForAll function.

 

Is there a way to perform this same simple operation but find matching records anywhere in the dataset? For example, if there were two matches, the first was record number 1 and the second match was number 10,000 I would want to update both of these.

 

Works but only up to the limit for non-delegated queries

 

Collect(colFind,
    Filter(DataSource, Area="Area 1")
);

ForAll(colFind,Patch(DataSource,
   LookUp(DataSource, ID = colFind[@ID]),
   {Area:"Area 2"}
   )
)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rebetcha
Level 10

Re: Update field if other field matches - delegation limit

Both functions (the collect function and the patch function) are non-delegable functions. So the you have to do the sorting in both. I dot know if you have another purpose for the collection. Otherwise you could get the items and patch them in one step instead of first collecting and then patching.

View solution in original post

6 REPLIES 6
Rebetcha
Level 10

Re: Update field if other field matches - delegation limit

If the number of items that match the comparison Area="Area 1" is below 500 (or 2000 if you use the preview upgraded data limit) you can look into sorting the data source you collect in the collect function Collect(colFind,Filter(Sort(Datasouce,Area, ascending),Area="Area 1")) in such a way that all the items are within the 500-2000 items of the sorted data source.
PhilD
Level 8

Re: Update field if other field matches - delegation limit

Thanks @Rebetcha

 

I thought this would work but I didn't get the results I expected but maybe I'm missing something.

 

In my list, I modified 5 records to so Area= "Area 1" so these are the last 5 modified records. With the app settings item limit set to 2, I tested the code below and was expecting 2 records to be collected and 2 to be patched. Instead 2 records were collected but nothing was patched. Evidently I have something wrong on the second part now...

 

Collect(colFind,
Filter(Sort(DataSource,Modified, Descending),Area="Area 1"));

ForAll(colFind,Patch(DataSource,
   LookUp(DataSource, ID = colFind[@ID]),
   {Area:"Area 2"}
   )
)
Rebetcha
Level 10

Re: Update field if other field matches - delegation limit

Both functions (the collect function and the patch function) are non-delegable functions. So the you have to do the sorting in both. I dot know if you have another purpose for the collection. Otherwise you could get the items and patch them in one step instead of first collecting and then patching.

View solution in original post

PhilD
Level 8

Re: Update field if other field matches - delegation limit

I see what you mean, that makes sense actually.

 

I used this and it worked! Thanks for pointing that out.

 

Collect(colFind,
Filter(Sort(DataSource,Modified, Descending),Area="Area 1"));

ForAll(colFind,Patch(DataSource,
   LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID]),
   {Area:"Area 2"}
   )
)
PhilD
Level 8

Re: Update field if other field matches - delegation limit

Somewhat of a related question. would it be also possible to patch a value from a column in the collection to a column in the matched records? What is shown below does not seem to work. 

 

Collect(colFind,
Filter(Sort(DataSource,Modified, Descending),Area="Area 1"));

ForAll(colFind,Patch(DataSource,
   LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID]),
   {Area:colFind.Title}
   )
)

 

PhilD
Level 8

Re: Update field if other field matches - delegation limit

I think I figured it out in case anyone else is following. Thanks @Rebetcha for helping point me in the right direction 🙂

 

This patches the plaintext value from colFind Area into the corresponding field in the DataSource for the matching record.

 

Collect(colFind,
Filter(Sort(DataSource,Modified, Descending),ID = 761));

ForAll(colFind,
Patch(DataSource,
   LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID]),
   {Area:LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID],Area )}
   )
)

And this patches the lookup column ID to a plain number field.

 

Collect(colFind,
Filter(Sort(DataSource,Modified, Descending),ID = 761));

ForAll(colFind,
Patch(DataSource,
   LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID]),
   {AlignmentID:LookUp(Sort(DataSource,Modified, Descending),ID = colFind[@ID],Alignment_x003a_ID.Id )}
   )
)

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,327)