cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FelipeCaru
Level 8

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

Re: Patch function without using "last submit"

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

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Patch function without using "last submit"

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
FelipeCaru
Level 8

Re: Patch function without using "last submit"

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

Super User
Super User

Re: Patch function without using "last submit"

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

View solution in original post

FelipeCaru
Level 8

Re: Patch function without using "last submit"

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

FelipeCaru
Level 8

Re: Patch function without using "last submit"

@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

 

Super User
Super User

Re: Patch function without using "last submit"

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,199)