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 / Not able to update exi...
Power Apps
Unanswered

Not able to update existing record using Patch and end up creating a new one

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all, 

 

I would really appreciate any advice regarding the following situation:

 

I have customised a SharePoint form with canvas apps and ended up having several forms that are submitted at different stages of the data entry process. Everything seems to be working as expected, except that in one process step I am not able to update an existing record in the SharePoint list. I am using the following "Save draft" button's OnSelect function to save data to the SharePoint:

 

/*set status variable that aumatically selects DefaultSelected value in the ABC status dropdown*/
Set(
 varStatus,
 "Draft"
);

/*Save form details into a variable varFormData so that I can patch items from other forms to it*/
Set(
 varFormData,
 If(
 varFormMode = FormMode.New, 
 Defaults(ABC),
 SharePointIntegration.Selected)
);
/*
I initiate varFormMode with OnView, OnNew, OnEdit Sharepoint integrations and use that variable in forms' ITEMS property, as such:
If(varFormMode = FormMode.New, Defaults(ABC), SharePointIntegration.Selected)
/*

/*Patch information that are associated to the forms' instances*/
Patch(
 ABC,
 varFormData,
 form_1.Updates, //FormMode = New. User inputs data manually in this form
 form_2.Updates, //FormMode = New. Data updated automatically based in inputs in form 1
 form_3.Updates, //FormMode = New
 form_Attachments.Updates //FormMode = New
);
/*Show notification messages to inform the user about operations without closing the canvas app, so that they could finish editing the form after saving a draft version of it*/
If(
 IsEmpty(Errors(ABC)),
 Notify(
 "Success. Your updates have been saved. You can continue editing the protocol or close it.",
 NotificationType.Success
 )
 ,
 Notify(
 First(Errors(ABC)).Message,
 NotificationType.Error
 )
)

 

When the function above is executed, the new record is created in the SharePoint list. When the function is executed again while editing the same form, the new record is created again with duplicate information. However, the ideal scenario would be:


1. User edits canvas app form

2. User clicks the "Save draft" button to save the progress and to create the item in the SharePoint list

3. User continues editing the form and clicks the "Save draft" button again

4. Result: the existing record in the SharePoint list is updated.

 

By the way, when the "Save draft" is clicked and the function above is executed, all forms remain in the New mode in an attempt to allow users to continue editing the form. I have tried changing the forms to the Edit mode after the "Save draft" button is clicked but that didn't help - the new record is created and the button with the function above is clicked.

 

Perhaps someone could help to troubleshoot, where could be the problem and why that function creates a new SharePoint list record instead of updating an existing one? Would sincerely appreciate any advice.

Categories:
I have the same question (0)
  • kritique Profile Picture
    16 on at

    Try Changing 

    SharePointIntegration.Selected

    to 

    ThisItem

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @kritique , 

    Thank you for the suggestion. For me ThisItem seems not to be available. After ThisItem is manually written, I get the error. Screenshot is below:

    image.png

     

  • kritique Profile Picture
    16 on at

    I might of missed it in the reading but where is this code placed?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @kritique , in the OnSelect property of the button in the Canvas App

    mantastg08876_0-1614811360554.png

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 
    My suggestion would be to go simple with this...you're trying to build all the existing form logic into your own formula.  You can do all of this from the Form itself and replace your entire formula with the SubmitForm function.


    First, if you've not seen it, I'd recommend watching my video on splitting forms WITHOUT losing the features of the EditForm.

     

    Then, once you have that set up properly, all you need to do is, in the Draft button, set a variable as such: 

    Set(formAction, "Draft")  

    Then in the DataCard that would indicate Draft or something else...put Coalesce(formAction, Self.Default) in the Update property.

    Then in the OnSuccess of the master Form (you'll get that if you watch the video), add this: Set(formAction, Blank()) along with the update to the glbCurrentRecord.

    Keep your form in Edit mode and initiate new records using the method described in the video.

    When the form submits it will then be in edit mode on the current record and can be edited.

     

    This is a change I know...but it works well and will simplify your app a lot.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    hi @RandyHayes ,

     

    thank you! yes, I am a subscriber to your channel! I might be too deep into the process to configure it the way you have recommended. Would like to try your method in the next project.

    Regarding your video:  I've noticed in your video there is no SharePoint Integration element (screenshot below). Just wanted to clarify if your method is applicable for customizing SharePoint forms in the Power App studio?

    mantastg08876_1-1614814808000.png

     

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, the video was based on a stand alone app, but it works equally as well in integration.

    The only real difference would be that, in the video, things all kind of start from a Gallery choice - that is essentially the SharePoint Integration.

    So things like the formula in the button to create a new record would be put into the OnNew action of the integration app.  In other words, things you want to do in the integration that are in the standalone, just get put into the Onxxx actions of the integration object.  

     

    And...thanks for subscribing!!  Really appreciate it and I promise there is new content coming.  I've got a bunch on the editing table right now.  Just need to fine 24 more hours in a day 😂

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard