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

ForAll with UpdateIf to Perform Collection Batch Update

I have a collection named "masterConeCollection" that has an "index" column and an "mastAct1PK" column.

I have another collection named "coneCollection" with an "act1PK" column that is generated from a gallery with a "TextInput3".

As you can see in the below code. I want to update the FirstN records that have a blank mastAct1PK column value with the act1PK in the user selected row found in coneCollection.

ForAll(
    RenameColumns(FirstN(Filter(masterConeCollection, IsBlank(mastAct1PK)), Value(TextInput3.Text)),
        "index", "filteredIndex"
    ),
    UpdateIf(masterConeCollection, 
        index = filteredIndex,
        {mastAct1PK: ThisItem.act1PK}
    )
)

The above code works, but writes over all records in the masterConeCollection. It does however write the proper amount of records defined by TextInput3. I need it to only write the FirstN amount of records that have a blank mastAct1PK value.

 

Please help and let me know if you have any questions. This one is complicated.

1 ACCEPTED SOLUTION

Accepted Solutions

Turns out I forgot about on visible code for the screen that deleted items from that collection when creating it. The code works fine after I added and if statement that references a last screen global variable.

 

Thanks for the help though. Always like to see others take.

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @cmalm ,

Although your logic looks fine, have a go as below at defining the ForAll after the FirstN

With(
   {
      colCone:
      RenameColumns(
         FirstN(
            Filter(
               masterConeCollection, 
               IsBlank(mastAct1PK)
            ), 
            Value(TextInput3.Text)
         ),
         "index", 
         "filteredIndex"
      )
   },
   ForAll(
      colCone,
      UpdateIf(
         masterConeCollection, 
         index = filteredIndex,
        {mastAct1PK: ThisItem.act1PK}
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

v-xida-msft
Community Support
Community Support

Hi @cmalm ,

Is the "index" column a Unique Type column (do not have duplicates value) in your "masterConeCollection"?

 

According to the formula that you mentioned, I could not find any syntax error with it. It seems that the logic is correct. If the "index" column is a Primary Key column in your "masterConeCollection", which does not have duplicates value, please take a try with the following formula:

ForAll(
       RenameColumns(
                     FirstN(Filter(masterConeCollection, IsBlank(mastAct1PK) || mastAct1PK=""), Value(TextInput3.Text)),
                     "index", 
                     "filteredIndex"
       ),
       Patch(
             masterConeCollection,
             LookUp(masterConeCollection, index = filteredIndex),
             {
               mastAct1PK: ThisItem.act1PK
             }
       )
)

 

Also please make sure the FirstN formula that you mentioned actually retrieve the proper amount of records whose mastAct1PK column is Blank.

 

Please use the Patch function to update the record in your "masterConeCollection" instead of the UpdateIf function.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@cmalm ,

A couple of options - please tag whoever you want to continue the thread with.

Turns out I forgot about on visible code for the screen that deleted items from that collection when creating it. The code works fine after I added and if statement that references a last screen global variable.

 

Thanks for the help though. Always like to see others take.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,179)