web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

My Patch function is overwriting SharePoint items instead of adding a new item

(0) ShareShare
ReportReport
Posted on by 134

Hi,

I am building an app for SharePoint data to replace our InfoPath form. The data is a contact list for "active" and "inactive" employees where employees have to go in and update their data periodically. We have flows that add new contacts when they are onboarded and changes them to "inactive" when offboarded. The problem I am having is when I go to test to add a new contact, the code is overwriting existing contacts with the new information I added. I only caught this because I had left out a field that captures the employee ID (firstName.lastName) and noticed when I searched for my test contact that it had overwritten the information for an inactive employee. My Patch code is below. I'm really hoping its just something wrong with my code and not a bug with PowerApps. 

LS579_1-1676648743515.png

 

So far, this only happens when I am adding a new contact and not when I am updating a current contact. I am very anxious to test this before getting any feedback now as I don't want to overwrite any other contact information... (I am downloading the list to Excel prior to testing, so I have back up information, but it will be a task to check so many contacts against two lists to see if I overwrote someone).

 

Thanks!

I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at
    Re: My Patch function is overwriting SharePoint items instead of adding a new item

    Your code is patching the item in the list that matches the browsegallery.selected.id

     

    Might I ask why you are using patch to submit the items from a form? Forms handle their info without using patch. Lots of people think forms are ugly so will hide them and have them reference a more personally laid out control set on a screen, but I have never seen anyone use a form for input, but offload its patching to another formula/control.

     

    You should also use one control for editing, and one for adding new employees as the default mode of the form being set to edit or new will change whether it edits the record or adds a record to the list

  • LS579 Profile Picture
    134 on at
    Re: My Patch function is overwriting SharePoint items instead of adding a new item

    I am using Patch because I have to update other columns in the SharePoint list that aren't on the form at the same time the contact is being added or updated. Everything after Team is not on the form, but it needs to update every time a new contact is added or someone updates their information. 

     

    So the browsegallery.selected.id option is supposed to be for my updates, not adding the new contact and I can't seem to find a record to use that wouldn't cause an error for the Patch function to work properly besides that. The Patch function worked fine when I was only using it to update, so I may need to create a separate form to add new contacts since it seems to be mixing up the commands. I was just hoping someone could help me figure out how to get it to patch a new record as well.

  • TheRobRush Profile Picture
    11,128 Moderator on at
    Re: My Patch function is overwriting SharePoint items instead of adding a new item

    Yah I would recommend just using two forms, and lose the patch. What you want to do is in the OnSuccess of each form

    UpdateContext({lastSub:Form1.LastSubmit.ID});
    UpdateIf(SharePointListName, ID=lastSub, {columns to patch})

    changing the names and stuff to match your source ofcourse. When you add an employee, use the form that is in newmode, when you edit one use the form that is in editmode

  • LS579 Profile Picture
    134 on at
    Re: My Patch function is overwriting SharePoint items instead of adding a new item

    Thank you. I will give that a try

  • Verified answer
    LS579 Profile Picture
    134 on at
    Re: My Patch function is overwriting SharePoint items instead of adding a new item

    To resolve this post, the above code did not want to work for me. Maybe I was entering something incorrectly, I'm not sure. Ultimately I ended up creating a separate screen to add the new items and using the Patch function with Defaults to submit the form. It works this way and it's not giving me any issues, so I'm happy with that as a solution. Thanks for everyone who posted to help! I appreciate all the suggestions!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 652 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 410 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 236

Last 30 days Overall leaderboard