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 / Patch a field in a dat...
Power Apps
Answered

Patch a field in a datasource, with a field from a collection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi 🙂

 

I have created a gallery with a TextInput. When the TextInput changes value (amounts) I want to collect the value to a collection along with the product name.

Collect(MyCollection, {ProductName: ThisItem.ProductName, Amount: TextInput1.Text})

This works.

 

 

 

I then want to push a button, to Patch all the updatede "Amounts" in "MyCollection" to the appropriate records in my datasource. But i cant get the basic patch command to work when i pull the field values from a collection.

 

 

Patch(MyDataSource,First(MyCollection).ProductName, {Amount: First(MyCollection).Amount})

There is something in the returns from the functions that conflics i think.

 

 

Aftert getting that to work, i need to look at getting it to work for all records in the collection, using ForAll or some "If" with a counter? Input on best practise is very welcome!

 

Help is much appriciated 🙂 Thanks

 

Categories:
I have the same question (0)
  • Verified answer
    BitLord69 Profile Picture
    914 on at

    Hi,

     

    Let's see if I can give you a helpful answer.

     

    So the datasource is called Productname, and a column within that datasource is also called Productname? From what you have written I assume it' so.

     

    The first parameter in a call to Patch is the datasource, i.e. the table in the database, and in your case it ought to be the same as the datasource for the gallery. 

     

    When you patch you have to make sure you get the correct record in the database to patch, and First(MyCollection).Productname doesnt' give you that. You would have to Filter/Lookup the datasource for it to work, or use

    ThisItem to get the actual record when you collect.

     

     

    Try changing to this:

     

    Collect(MyCollection, {Record: ThisItem, Amount: TextInput1.Text})
    Patch(ProductName,First(MyCollection).Record, {Amount: First(MyCollection).Amount})

     

    Alternatively:

    Collect(MyCollection, {Productname: ThisItem.Productname, Amount: TextInput1.Text})
    Patch(Productname, Lookup(Productname, First(MyCollection).ProductName = Porductname), {Amount: First(MyCollection).Amount})

     

    Good luck!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi BitLord69,

     

    Thank you for the reply.

     


    @BitLord69 wrote:

    Hi,

     

     

    ...

     

    So the datasource is called Productname, and a column within that datasource is also called Productname? From what you have written I assume it' so.

     


    Thats a typo on my part during translation. DataSource is named differently in real life 🙂

     

    Changing to the RecordID on ThisItem solved the Problem. Thank you for the help.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 429 Most Valuable Professional

#2
11manish Profile Picture

11manish 191 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 122 Super User 2026 Season 2

Last 30 days Overall leaderboard