cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nurbmr
Helper I
Helper I

Patch a new record and update existing record

Hi, 

 

I have a form that will be filled with information about a product, with Button1 as submit button. What I want the button to do is to patch new record of the product to Database1 and update an existing record of the product in another db, Database2. Details are as below.

 

Database1

ProductID (DataCardValue1)ProductName (DataCardValue2)

Date

(DataCardValue3)

54321Pencil22/4/2021

 

Database2, current existing record

ProductIDProductNameStatusDate
54321PencilIn store

19/4/2021

 

Button1 OnSelect property

 

Patch(Database1, Defaults(Database1),{ProductID:DataCardValue1.Text, ProductName:DataCardValue2.Text, Date:DataCard3.SelectedDate});

Patch(Database2, LookUp(Database2, ProductID:DataCardValue1.Text),{Status:"Removed",Date:DataCard3.SelectedDate});

 

 What I want this to achieve is when Button1 is selected, it will create a new record in Database1 and in Database2, update the 'Status' of the said product to "Removed" and update the 'Date' to the date as selected in DataCard3. 

 

The problem here is the second patch function is not working somehow. It's showing errors. How do I go about this? 

 

Thank you in advance. 

2 ACCEPTED SOLUTIONS

Accepted Solutions
KrishnaV
Community Champion
Community Champion

Hi @nurbmr ,

 

OnSuccess property of the form write the second patch:

Patch(Database2, LookUp(Database2, ProductID:DataCardValue1.Text),{Status:"Removed",Date:DataCard3.SelectedDate});

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

View solution in original post

RandyHayes
Super User
Super User

@nurbmr 

This type of thing is done in the OnSuccess action of the Form.  However, you do not appear to be doing a SubmitForm function in that OnSelect action.

So, your OnSelect action of the button should be : SubmitForm(yourFormName)

 

Then in the OnSuccess action of the Form, you should have the following: 

UpdateIf(Database2, 
    ProductID = yourFormName.LastSubmit.ProductID,
    {Status: "Removed",
     Date: yourFormName.LastSubmit.DateColumn
    }
);

Replace the ProductID and DateColumn with the names of the fields in your form that contain those values.

Do not rely on the DataCardValue controls on a form as they can easily change and cause you errors.  The LastSubmit property of the form will be the correct information that was submitted.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

6 REPLIES 6
KrishnaV
Community Champion
Community Champion

Hi @nurbmr ,

 

OnSuccess property of the form write the second patch:

Patch(Database2, LookUp(Database2, ProductID:DataCardValue1.Text),{Status:"Removed",Date:DataCard3.SelectedDate});

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
RandyHayes
Super User
Super User

@nurbmr 

This type of thing is done in the OnSuccess action of the Form.  However, you do not appear to be doing a SubmitForm function in that OnSelect action.

So, your OnSelect action of the button should be : SubmitForm(yourFormName)

 

Then in the OnSuccess action of the Form, you should have the following: 

UpdateIf(Database2, 
    ProductID = yourFormName.LastSubmit.ProductID,
    {Status: "Removed",
     Date: yourFormName.LastSubmit.DateColumn
    }
);

Replace the ProductID and DateColumn with the names of the fields in your form that contain those values.

Do not rely on the DataCardValue controls on a form as they can easily change and cause you errors.  The LastSubmit property of the form will be the correct information that was submitted.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
KrishnaV
Community Champion
Community Champion

Hi @nurbmr ,

 

did that help you, please let me know if you still see any issues happy to help you.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@RandyHayes Thank you for your help and tips. 

Hi @KrishnaV ,

 

Many thanks for your help.

Hi @RandyHayes , 

I've encountered an error. I have two forms with two different datasources but they will be submitted as one record for another database, Database3. Here, I'm using one submit button for it with OnSelect property.

Submit(Form1) and Submit(Form2)

 I only use the 'UpdateIf' function as you suggested on the OnSuccess property for Form2. The errors that comes up are:

1. It did not update the status in Database1,

2. An error box pop up, saying a field in Form1 is empty when it's actually been filled. 

 

Might be worth to note that only 2 out of 3 of the Form2 table column are on the form, for it to be filled. 

 

I hope this is clear and easy to understand. 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (1,506)