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.
Solved! Go to Solution.
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(....)})
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.
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(....)})
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
@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.
User | Count |
---|---|
137 | |
132 | |
79 | |
75 | |
72 |
User | Count |
---|---|
210 | |
200 | |
69 | |
62 | |
53 |