cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rajkumar88
Level: Powered On

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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

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

@rajkumar88 

 

I was in an impression that you are submitting the forms first and then trying to Patch this record. As you have unsubmitted forms, instead of using lastsubmit, you have to use updates to get the results from each form and perform a final update.
 
Please modify your expression as:

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

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

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

 

Hope this Helps!

 

 

View solution in original post

13 REPLIES 13
Super User
Super User

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

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
Level: Powered On

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

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.
Super User
Super User

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

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!

Super User
Super User

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

@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.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
rajkumar88
Level: Powered On

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

@yashag2255,

 

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

rajkumar88
Level: Powered On

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

@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)

 

Super User
Super User

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

@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
Level: Powered On

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

@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))

Super User
Super User

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

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.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 71 members 3,453 guests
Please welcome our newest community members: