cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FelipeCaru
Advocate V
Advocate V

Patch function without using "last submit"

Hello all,

I have a, hopefully, brief question regarding the PATCH function. In an App I made, I have a form that is both saved to 'file1' via submitform plust some parts of it via PATCH, after that, in 'file2', with the code:

Fecha_x0020_Evaluacion: form_ELT.LastSubmit.'Comienzo Real'

Now, I have another app where I want to save via patch function, however, it is not saving via submitform thus the 'last submit' of the formula won't work. What can I do?

The App is a survey, in different parts, where item A part 1 is answered, then go to next screen and answer part 2. When changing screen from pt1 to pt2, it should save the answers of p1, in another file not the same where it reads the template, hence, the PATCH I am trying to use.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@FelipeCaru 

Right, so you want to replace all of those form references to be your actual controls.

Ex. if you have a txtInput1 and txtInput2, and a toggle1 and a dropdown1 on your screen, then your Patch might be something like this:

Set(lastPatch, 
       Patch(dataSource, 
                 Defaults(dataSource), 
                 {
                     txtVal1: txtInput1.Text,
                     txtVal2: txtInput2.Text,
                     boolVal: toggle1.Value,
                     txtDrop: DropDown1.Value
                 }
              )
)

Of course, your actual colum names would be whatever is in the data source and your control names would be whatever are the controls that will "map" to them.

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

@FelipeCaru 

Patch actually returns a record - the record that it patched.

So, what you can do is capture the Patch in a variable to use when you need.

Set(lastPatch, Patch(yourPatchFormulaHere))

Then later you can use any information you need from that.  Like, lastPatch.ID, etc.

 

I hope that 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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

@RandyHayes 

I am not entirely sure how to do the Patch function, however, since the one I know goes like:

Patch(log,
    Defaults(log),
    {IDOrden: form_ELT.LastSubmit.'ID Orden',
    ComienzoReal: form_ELT.LastSubmit.'Comienzo Real',
    FinReal: form_ELT.LastSubmit.'Fin Real',
    Completado: form_ELT.LastSubmit.Completado,
    Comentarios: form_ELT.LastSubmit.Comentarios,
    LastModifiedBy: form_ELT.LastSubmit.LastModifiedBy,
    LastModifiedAt: form_ELT.LastSubmit.LastModifiedAt})

So, going by the formula Set(lastPatch, Patch(yourPatchFormulaHere)), it would end as:

Set(lastPatch,
Patch(file2,
    Defaults(file2),
    {IDOrden: form_ELT.LastSubmit.'ID Orden',
    ComienzoReal: form_ELT.LastSubmit.'Comienzo Real',
    FinReal: form_ELT.LastSubmit.'Fin Real',
    Completado: form_ELT.LastSubmit.Completado,
    Comentarios: form_ELT.LastSubmit.Comentarios,
    LastModifiedBy: form_ELT.LastSubmit.LastModifiedBy,
    LastModifiedAt: form_ELT.LastSubmit.LastModifiedAt}))

Which I still get confused/stuck since I won't have a submitted form.

@FelipeCaru 

Right, so you want to replace all of those form references to be your actual controls.

Ex. if you have a txtInput1 and txtInput2, and a toggle1 and a dropdown1 on your screen, then your Patch might be something like this:

Set(lastPatch, 
       Patch(dataSource, 
                 Defaults(dataSource), 
                 {
                     txtVal1: txtInput1.Text,
                     txtVal2: txtInput2.Text,
                     boolVal: toggle1.Value,
                     txtDrop: DropDown1.Value
                 }
              )
)

Of course, your actual colum names would be whatever is in the data source and your control names would be whatever are the controls that will "map" to them.

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

@RandyHayes 

OOoooh I get it now. Didn't know I could use the control itself like that. Thank you, just tested it and worked perfectly.

@RandyHayes 

As an additional question:

Is it possible to store each form answer saved as patch as  a variable, and only when the "survey" is finished, it writes each answer to the file? Like:

  • Q1 -> click next && save answer set 1 as "a"
  • -> Q2 -> click next && save answer set 2 as "b"
  • ...
  • -> Qn -> click finish && save answer set n as "n" -> write to file answer set "a", then "b", ..., then "n" -> go back to (x) screen

 

@FelipeCaru 

You could...however, just because a user has moved on from a screen doesn't mean that you have to capture things into variables (don't overuse variables if you can avoid it).

If a user has typed in something in TextBox1 on screen 1 and then moves along through several screens to arrive at, let's say, screen 6 where there is a save button - the Text in TextBox1 is still there and can be referenced by any formula or control on that screen.

So a Patch(datasource, record, {TextVal: TextBox1.Text}) is perfectly valid.

Trying to capture the value of textbox1 in a variable to reference it later is overkill and can lead to confusion. 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,580)