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 / unable to save and upd...
Power Apps
Answered

unable to save and update using one button only. Please help me

(0) ShareShare
ReportReport
Posted on by 397

I have 4 screens with different field types such as radio buttons, text fields. I am able to submit content using below funtion, however if I try to edit exisiting one, then it created new item in SPlist.

 Below is the code I am currently using to save the content. How can I use if it is newform then save new item and if it is an exisiting item then update that item only instead of creating new item. 

Patch(Employee,Defaults(Employee),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.LastSubmit,Form2_6.LastSubmit,
{
ManagerStatus:{Value:"Pending"}

}
);Navigate(fr_ManagerLandingscreen,ScreenTransition.None)

 

@RandyHayes @v-bacao-msft @yashv @yashag2255 

Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @rajkumar88 

    This might be happening because of Defaults() function in the Patch formula. Defaults is used when you want to create a new record. In case you are looking for something to update an already existing record, you can use the below expression:

    Patch(Employee,LookUp(Employee, EmployeeName = "EmpName"),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.LastSubmit,Form2_6.LastSubmit,
    {
    ManagerStatus:{Value:"Pending"}
    
    }
    );Navigate(fr_ManagerLandingscreen,ScreenTransition.None)

    Here, we are using lookup to get the record which we want to update. Please replace (EmployeeName = "EmpName") in the lookup with the specific condition to get certain record.

    For more information about the Patch, please refer: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • rajkumar88 Profile Picture
    397 on at
    Hi ,

    Thanks for your response. If I understand correctly, if ex: createdby.email=userinfo// a variable already set to user email

    Then ManagerStatus:{Value:"Pending"}, test: datacardvalue.selected, choice: datacardvalue1.selected


    And if it is not true then create new record to splist using Form1_2.updates,Form2_2.updates,Form3_1.updates,Form2_6.Updates,

    ??
    What I really trying to avhieve is that there an item already exists then it should update all the fields whatever changed by the user to that record only. And if there is no record created, then it should create a new record.
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @rajkumar88 

     

    You can use an IF loop for doing that, please follow the below expression:

    If(IsEmpty(LookUp(Employee, EmployeeName = "EmpName")),Patch(Employee,Defaults(Employee),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.LastSubmit,Form2_6.LastSubmit,
    {
    ManagerStatus:{Value:"Pending"}
    
    }
    );Navigate(fr_ManagerLandingscreen,ScreenTransition.None),Patch(Employee,LookUp(Employee, EmployeeName = "EmpName"),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.LastSubmit,Form2_6.LastSubmit,
    {
    ManagerStatus:{Value:"Pending"}
    
    }
    );Navigate(fr_ManagerLandingscreen,ScreenTransition.None))

    This checks if the records exists with the specified criteria and then creates/ updates records.

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

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

    @rajkumar88 

    Did @yashag2255  help you out with your issue?

    Looks like a good formula.  One other option that you can use when dealing with existing vs new records is the Coalesce function:

     

    Patch(Employee,
     Coalesce(LookUp(Employee, EmployeeName = "EmpName"), Defaults(Employee)),
     Form1_2.LastSubmit,
    Form2_2.LastSubmit,
    Form3_1.LastSubmit,
    Form2_6.LastSubmit, { ManagerStatus:{Value:"Pending"} }
    );
    Navigate(fr_ManagerLandingscreen,ScreenTransition.None)

    I am assuming from the chain here that you actually intend to Submit 4 separate forms, presumably tied to the Employee datasource and then to re-patch with that same form data.

     

    If so, then the "determination" of if a record exists or not is a moot point as the first form you submitted would have created the record you are wanting to patch.

    In that case, I would alter the formula to the following:

    Patch(Employee,
     LookUp(Employee, ID = Form1_2.LastSubmit.ID),
     Form1_2.LastSubmit,
     Form2_2.LastSubmit,
     Form3_1.LastSubmit,
     Form2_6.LastSubmit,
     {
     ManagerStatus:{Value:"Pending"}
     }
     );
    Navigate(fr_ManagerLandingscreen,ScreenTransition.None)

    Lots of good formulas for you...let us know what helps.

     

     

  • rajkumar88 Profile Picture
    397 on at

    @yashag2255,

     

    Do I need to use .lastsubmit or .updates is also fine? either way it's not saving any record.

  • rajkumar88 Profile Picture
    397 on at

    @RandyHayes,

     

    With YaSH SOLUTION, I still trying to fix the issue, because it's not saving the content, however atleast for now it's not creating the duplicate account. I am not sure if this is because of .lastsubmit issue? Do I need to use .update instead?

     

    And also with respect to your  function, will it also save new record if that doesn't exist? Do I need to use ID in lookup?

    Patch(Employee,
     LookUp(Employee, ID = Form1_2.LastSubmit.ID),
     Form1_2.LastSubmit,
     Form2_2.LastSubmit,
     Form3_1.LastSubmit,
     Form2_6.LastSubmit,
     {
     ManagerStatus:{Value:"Pending"}
     }
     );
    Navigate(fr_ManagerLandingscreen,ScreenTransition.None)

     

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    @rajkumar88 

     

    Using .lastsubmit should work in your case. I am assuming that you have submitted the edit forms first and then you are trying to do a patch. The major difference between .lastsubmit and .update is that "lastsubmit" gets all the attributes corresponding to a form after submit, while .updates gets back only changed attributes.
     
    Are you seeing any error with the formula? Please let us know if any.

     

  • rajkumar88 Profile Picture
    397 on at

    @yashag2255,

     

    No I don't see any error. I tried to save new record too and still there is no luck. And also for saving new record, will .lastsubmit do that trick? Below is my function I am using.

     

    If(IsEmpty(LookUp(EmployeePerformance, Lower('Created By'.Email) =Lower(userinfo) )),Patch(EmployeePerformance,Defaults(EmployeePerformance),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.LastSubmit,Form2_6.LastSubmit,
    {
    ManagerStatus:{Value:"Pending"}

    }
    );Navigate(fr_ManagerLandingscreen,ScreenTransition.None),Patch(EmployeePerformance,LookUp(EmployeePerformance, Lower('Created By'.Email) =Lower(userinfo)),Form1_2.LastSubmit,Form2_2.LastSubmit,Form3_1.Lastsubmit,Form2_6.LastSubmit,
    {
    ManagerStatus:{Value:"Pending"}

    }
    );Navigate(fr_ManagerLandingscreen,ScreenTransition.None))

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @rajkumar88 

     

    I carried out a simple test on my side and I am able to save the results on the basis of last submit values through an Edit Form.
     
    Can you please confirm few details:
    1) The four edit forms that you mentioned in the post, are they updating same data-source or multiple data sources?
    2) Have you submitted the four forms individually before performing this Patch operation?
    3) Also, please verify what LookUp(EmployeePerformance, Lower('Created By'.Email) =Lower(userinfo) ) is returning? You can do that by creating a temporary button and use the formula to create a collection just to see the data.
    ClearCollect(testcoll,LookUp(EmployeePerformance, Lower('Created By'.Email) =Lower(userinfo) ))
    Please verify if this is returning the correct record.
  • rajkumar88 Profile Picture
    397 on at
    @yashag2255,

    1. I am using single data source to save all the content, but I have 4screens due tow whichever ypu are seeing four forms.
    2. I haven’t submitted four forms individually before. Part of my request is to patch all four forms and submit content to dharepoint list. // this is for new record. And on the same button, if there a record already available on his name, then it should just update the existing one intead of creating new one.

    3. I tried with your suggestion and it is returning results properly.

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,070

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 608

Last 30 days Overall leaderboard