cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MostafaGamal
Helper IV
Helper IV

How to combine patch and form in one record

Hi all, 

Im building a new application in PowerApps using 2 different of input drop down and a form to enter the data in it and this data will be recorded in SharePoint 

but when i submit the data it saved in 2 different rows , i would like the input in the drop down and the form to be recorded in the same record ( row in the SharePoint ) 

How i can do that ? 

 

Capture4.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @MostafaGamal :

Do you want to use SubmitForm() and Patch() to update the same record at the same time?

Please try this code:

 

SubmitForm(yourfrom);/*Step1:submit your form*/
Patch(yourdatasource,
     First(Sort(yourdatasource,Modified,Descending)),/*Step2:Find the record that has just been updated and update it with the Patch function*/
     {Column1:"xxx",Column2:"XXX"}
)

 

Modified is the standard field of SP list, it saves the modification time of the record. So we can use it to find the recently modified records.

Best Regards,

Bof

View solution in original post

7 REPLIES 7
Drrickryp
Super User
Super User

Hi @MostafaGamal 

Please show the Patch() function you are using in your app.  What is the OnSelect property of your submit button and where are you placing your Patch() function?

@Drrickryp Hi, 

here is a photo of the formula on select, i want to save the data in the same row ( record )

I also used " Concurrent(Patch('CM Trial 1',LookUp('CM Trial 1', ID = Form3.LastSubmit.ID);{Department:Dropdown1.SelectedText.Value}),SubmitForm(Form3);ResetForm(Form3)) " 

but still the same problem saving the data in 2 rows 

 

powerapps1.PNG

 

 @MostafaGamal 

There should only be SubmitForm(Form3) in the button. I cannot think of any good reason for chaining functions with a SubmitForm() as you don't want them to execute unless the submission succeeds.   Move the Patch and the ResetForm(Form3) to the OnSuccess property of the form and delete the Concurrent() function. The OnSuccess property of Form3 should be:

 

 

Patch(
      'CM Trial 1',LookUp(
                           'CM Trial 1', ID = Form3.LastSubmit.ID
                     ),{Department:Dropdown1.SelectedText.Value}
 );
ResetForm(Form3)

 

 

There are probably several reasons why you are not getting the result want. 

  • The logic of the patch requires that the Form has been successfully submitted so that the last submitted record's ID is exposed. It cannot use it if it doesn't exist.
  • There is a semicolon between the LastSubmit.ID) and {  and it should be a comma. 
  • Also you want to move the ResetForm() function into the OnSuccess property so the form doesn't automatically get reset if it fails. 
  • There is no need for the Concurrent() function in the formula. 

@Drrickryp it gives me the following error and only record the form data 

 

powerapps2.PNG 

v-bofeng-msft
Community Support
Community Support

Hi @MostafaGamal :

Do you want to use SubmitForm() and Patch() to update the same record at the same time?

Please try this code:

 

SubmitForm(yourfrom);/*Step1:submit your form*/
Patch(yourdatasource,
     First(Sort(yourdatasource,Modified,Descending)),/*Step2:Find the record that has just been updated and update it with the Patch function*/
     {Column1:"xxx",Column2:"XXX"}
)

 

Modified is the standard field of SP list, it saves the modification time of the record. So we can use it to find the recently modified records.

Best Regards,

Bof

@v-bofeng-msft  thanks it works now thanks alot 🙂 

Worked for me after I changed the semicolon after LookUp to a comma.

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.

Users online (2,668)