cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Steelman70
Level 10

Using the values returned by behaviour formulas (i.e. Patch)

How can we read/use the values returned by behaviour formulas such as Patch?

 

The reference article mentions this: "The return value of Patch is the record that you modified or created. If you created a record, the return value may include properties that the data source generated automatically."

 

I am not sure how to get the return value when associating a patch with an OnSelect of say a button.  This is useful to get the auto generated ID of a new item from a SharePoint list for example.

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff murali
PowerApps Staff

Re: Using the values returned by behaviour formulas (i.e. Patch)

That's a very strong assumption. It may work. But the right way to do it is to simply UpdateContext the return value of Patch

UpdateContext({Submitted: Patch(....)})

View solution in original post

11 REPLIES 11
Microsoft DeanWang
Microsoft

Re: Using the values returned by behaviour formulas (i.e. Patch)

Hi,

 

You can use “Navigate(ViewScreen,ScreenTransition!Fade,{Record:ThisItem})” to create a record.

 

A detailed demo about how to browse for a record, display details about that record, and edit or create a record:

https://powerapps.microsoft.com/en-us/tutorials/working-with-forms/#browse-records

 

Thanks,

 

Dean Wang

UB400
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

Dean, thank you for your response. From my understanding of your response you have shown an alternative way to create a record. I'm in a similar position to the orignal poster. 

 

If i use the Patch(DataSource, Defaults... command, how do I get the record ID on the newly created record? I need it because I want to pass on this new record ID to the next screen so that I can continue patching in more data into the newly created record.

 

I can't seem to find any information on how to colleact these values that are returned from running these commands.

Meneghino
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

Hi @UB400

This is Steelman70, but I changed my username.

I have found how to do this, and it seems to work.

Basically, once you Patch with Defaults, your newly created record is the last in the data source, so what I do is to add an UpdateContext to get the ID of the last record in the data source.  This should be the OnSelect of your save button:

Patch(MyDataSource, Defaults(MyDataSource), {MyColumn1: MyData etc....}); UpdateContext({MyNewlyCreatedRecordID: Last(MyDataSource).ID})

Please let me know if this works for you too.

PowerApps Staff murali
PowerApps Staff

Re: Using the values returned by behaviour formulas (i.e. Patch)

That's a very strong assumption. It may work. But the right way to do it is to simply UpdateContext the return value of Patch

UpdateContext({Submitted: Patch(....)})

View solution in original post

Meneghino
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

Wow @murali, thank you!  I had been waiting for that answer for about 3 months (my first post on this topic on the documentation page and this thread as Steelman70)

As @UB400 mentioned, there is no indication of this anywhere in the documentation, at least that I have found.

Many thanks!

UB400
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

Thank you @murali I really appreciate yours and @Steelman70 input. My apologies for my follow up question (I'm still very new to PowerApps).

 

This is the formula I came up with:

 

UpdateContext({Submitted: Patch(ConsultantList, Defaults(ConsultantList), {Title:" ",ConsultantFullName:TextInput1.Text,ConsultantAddressLine1:TextInput2.Text,ConsultantAddressCity:TextInput3.Text})});Navigate( Screen7, None,Submitted)

 

I'm able to see the value of the submitted.ID on the same page after the above command runs, but I'm not quite sure how to pass it on to the next screen. When I add a Textbox on the new screen and use Submitted.ID as the "Text" value, I get the yellow triangle for invalid name.

 

Please advise.

PowerApps Staff murali
PowerApps Staff

Re: Using the values returned by behaviour formulas (i.e. Patch)

Context variables are bound to the screen on which they are created. They can however be passed around to other screens via Navigate. 

 

e.g. Navigate(Screen7, ScreenTransition.None, {Submitted: Submitted})

 

which stands for: take the value of Submitted and pass it to Screen2. On Screen2, you can now use Submitted just like before.

 

Hope this helps.

 

Thanks

Murali

Highlighted
Meneghino
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

@murali is ablsoutely correct.

I just wanted to add to be careful when using the same context variable name in two or more different screens.  If you then change the value of the variable in the second screen for any reason, the value of that variable in the other screens is not affected.

Basically you can end up in a situation where one context variable has a different value in each of your screens where it is used.

To avoid this confusion I normally do not use the same context variable name in two different screens:

e.g. Navigate(Screen7, ScreenTransition.None, {Returned: Submitted})
UB400
Level 10

Re: Using the values returned by behaviour formulas (i.e. Patch)

@murali and @Meneghino thank you so much for your help with this. That works! You guys are awesome.

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 (4,694)