cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thomaspp
Helper I
Helper I

ForAll with Patch

I'm trying to update column values for multiple records in my data source by using ForAll and Patch, but I need help with the syntax

ForAll( Filter( PlannedMData, Part = DataCardValue18_2.Text ), Patch( PlannedMData, { 'In stock': DataCardValue9_2 }) )

 

It gives me the error "This function cannot operate on the same data source that is used in ForAll".

How to fix?

2 ACCEPTED SOLUTIONS

Accepted Solutions
StalinPonnusamy
Super User
Super User

Simplified version

ForAll(
        RenameColumns(
        Filter(PlannedMData,Part = DataCardValue18_2.Text),
        "ID",
        "newID"
    ),
UpdateIf(PlannedMData, ID = newID, { 'In stock': DataCardValue9_2 })
)

View solution in original post

StalinPonnusamy
Super User
Super User

Hi @thomaspp 

 

  • It filters the Data source based on the part number
  • Loop through the list
  • Patch the data source
ForAll(
        RenameColumns(
        Filter(PlannedMData,Part = DataCardValue18_2.Text),
        "ID",
        "newID"
    ),
Patch(
        PlannedMData,
        LookUp(
            PlannedMData,
            ID = newID
        ),
        { 'In stock': DataCardValue9_2 }
    )
)

 

This approach same as the first one using the collection. 

 

View solution in original post

7 REPLIES 7
StalinPonnusamy
Super User
Super User

Hi @thomaspp 

 

Please try this

 

ClearCollect(
    TempCollection,
    RenameColumns(
        Filter(PlannedMData,Part = DataCardValue18_2.Text),
        "ID",
        "newID"
    )
);
ForAll(
    TempCollection,
    Patch(
        PlannedMData,
        LookUp(
            PlannedMData,
            ID = newID
        ),
        { 'In stock': DataCardValue9_2 }
    )
)

 

StalinPonnusamy
Super User
Super User

Simplified version

ForAll(
        RenameColumns(
        Filter(PlannedMData,Part = DataCardValue18_2.Text),
        "ID",
        "newID"
    ),
UpdateIf(PlannedMData, ID = newID, { 'In stock': DataCardValue9_2 })
)

Thanks, I tried but still only the one item is updated.
The button is in an edit form for gallery items and want to update all other items in the gallery that share the same Part name. Does that give some clue?

thomaspp
Helper I
Helper I

Also, I'm not using a collection. PlannedMData is my data source

thomaspp
Helper I
Helper I

I think I've gotten closer to the solution:

 

Patch( PlannedMData, First(Filter( PlannedMData, Part = DataCardValue18_2.Text )), { 'In stock': DataCardValue9_2.Text } )

This updates the first record correctly. But I need all records with the same Part name, i.e. "DataCardValue18_2.Text" to be updated.
How to?

StalinPonnusamy
Super User
Super User

Hi @thomaspp 

 

  • It filters the Data source based on the part number
  • Loop through the list
  • Patch the data source
ForAll(
        RenameColumns(
        Filter(PlannedMData,Part = DataCardValue18_2.Text),
        "ID",
        "newID"
    ),
Patch(
        PlannedMData,
        LookUp(
            PlannedMData,
            ID = newID
        ),
        { 'In stock': DataCardValue9_2 }
    )
)

 

This approach same as the first one using the collection. 

 

thomaspp
Helper I
Helper I

Both work with a few adjustments. Thank you

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,671)