cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mrjrobinson
Frequent Visitor

Data not updating from edit in Gallery

Hi There,

 

First off I am a novice to all of this so please bare with me. 

 

I have created a gallery with a edit button, when I click on this the fields become "Editable" and I make my changes to the record. When I click on my save button this writes to my spreadsheet connection but as a new entry instead of updating the existing entry. I have watched a lot of videos to piece this together. Here is my formula:


UpdateContext({EditRecord: " "});Patch('Member Tracker',{Membership_x0020_Number:ThisItem.Membership_x0020_Number},
{Member_x0020_Name: MembersNameInputField.Text,
Membership_x0020_Number: MembershipNumberInputField.Text,
Membership_x0020_Type:MembershipTypeInputField.Text,
Member_x0020_Status:MemberStatusInputField.Text,
Payment_x0020_Date:PaymentDateInputField.Text,
Email_x0020_Address:EmailAddressInputField.Text,
Mobile_x0020_Number:ContactNumberInputField.Text,
Notes:NotesInputField.Text})

 

Any help you can provide would be great!

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@mrjrobinson 

Hello there and welcome to the PowerApps community.  I can see the reason why your PATCH is not updating the current record as you expected.  It is because of this code segement in the 2nd argument of PATCH.

 

{Membership_x0020_Number:ThisItem.Membership_x0020_Number}

 

The 2nd argument of PATCH references the record to be updated.  What you have done is created a whole new record by putting some data between the curly brackets { }.  Instead what you should do is replace it with this code.

 

ThisItem

  

ThisItem returns the current record in the gallery the Save button is placed within and it is a record data type.  If you are familar with LookUp it achieves the same result current record like this.

 

LookUp('Member Tracker',ID=ThisItem.ID)

 

To recap, here's the full code you should use.

 

UpdateContext({EditRecord: " "});
Patch(
    'Member Tracker',
    ThisItem,
    {
        Member_x0020_Name: MembersNameInputField.Text,
        Membership_x0020_Number: MembershipNumberInputField.Text,
        Membership_x0020_Type:MembershipTypeInputField.Text,
        Member_x0020_Status:MemberStatusInputField.Text,
        Payment_x0020_Date:PaymentDateInputField.Text,
        Email_x0020_Address:EmailAddressInputField.Text,
        Mobile_x0020_Number:ContactNumberInputField.Text,
        Notes:NotesInputField.Text
    }
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

6 REPLIES 6
PowerAddict
Super User
Super User

Can you try this version of Patch?

UpdateContext({EditRecord: " "});Patch('Member Tracker', ThisItem,
{Member_x0020_Name: MembersNameInputField.Text,
Membership_x0020_Number: MembershipNumberInputField.Text,
Membership_x0020_Type:MembershipTypeInputField.Text,
Member_x0020_Status:MemberStatusInputField.Text,
Payment_x0020_Date:PaymentDateInputField.Text,
Email_x0020_Address:EmailAddressInputField.Text,
Mobile_x0020_Number:ContactNumberInputField.Text,
Notes:NotesInputField.Text})

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)
mdevaney
Super User
Super User

@mrjrobinson 

Hello there and welcome to the PowerApps community.  I can see the reason why your PATCH is not updating the current record as you expected.  It is because of this code segement in the 2nd argument of PATCH.

 

{Membership_x0020_Number:ThisItem.Membership_x0020_Number}

 

The 2nd argument of PATCH references the record to be updated.  What you have done is created a whole new record by putting some data between the curly brackets { }.  Instead what you should do is replace it with this code.

 

ThisItem

  

ThisItem returns the current record in the gallery the Save button is placed within and it is a record data type.  If you are familar with LookUp it achieves the same result current record like this.

 

LookUp('Member Tracker',ID=ThisItem.ID)

 

To recap, here's the full code you should use.

 

UpdateContext({EditRecord: " "});
Patch(
    'Member Tracker',
    ThisItem,
    {
        Member_x0020_Name: MembersNameInputField.Text,
        Membership_x0020_Number: MembershipNumberInputField.Text,
        Membership_x0020_Type:MembershipTypeInputField.Text,
        Member_x0020_Status:MemberStatusInputField.Text,
        Payment_x0020_Date:PaymentDateInputField.Text,
        Email_x0020_Address:EmailAddressInputField.Text,
        Mobile_x0020_Number:ContactNumberInputField.Text,
        Notes:NotesInputField.Text
    }
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney would appreciate acknowledgement if someone posts the same suggested solution before you 🙂

No hard feelings, just a suggestion. Hope you have a great day!

@PowerAddict 

Sometimes we are posting at the same time so it happens.  I typically open the reply window, go to my app testing environment to build a test and then post a response.  But yes, I do acknowledge that you also have a correct solution here.

Yup, has happened to me before. No worries!

Thank you very much for your assistance!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,589)