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

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

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

6 REPLIES 6
KrishnaV
Super User III
Super User III

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

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

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
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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (44,773)