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) |
54321 | Pencil | 22/4/2021 |
Database2, current existing record
ProductID | ProductName | Status | Date |
54321 | Pencil | In 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.
Solved! Go to Solution.
Hi @nurbmr ,
OnSuccess property of the form write the second patch:
Patch(Database2, LookUp(Database2, ProductID:DataCardValue1.Text),{Status:"Removed",Date:DataCard3.SelectedDate});
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.
Hi @nurbmr ,
OnSuccess property of the form write the second patch:
Patch(Database2, LookUp(Database2, ProductID:DataCardValue1.Text),{Status:"Removed",Date:DataCard3.SelectedDate});
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.
Hi @nurbmr ,
did that help you, please let me know if you still see any issues happy to help you.
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.
User | Count |
---|---|
260 | |
110 | |
98 | |
56 | |
40 |