Skip to main content

Notifications

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 128

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!

  • Verified answer
    LS579 Profile Picture
    LS579 128 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!

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

    Thank you. I will give that a try

  • TheRobRush Profile Picture
    TheRobRush 11,121 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
    LS579 128 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
    TheRobRush 11,121 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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,434

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,722

Leaderboard