cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Steelman70
Power Participant
Power Participant

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

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
DeanWang
Microsoft
Microsoft

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

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
Community Champion
Community Champion

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.

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
Community Champion
Community Champion

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!

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.

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

Meneghino
Community Champion
Community Champion

@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})

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,170)