web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using the values retur...
Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on by 873

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.

Categories:
  • DeanWang Profile Picture
    Microsoft Employee on at

    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 Profile Picture
    356 on at

    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 Profile Picture
    6,949 on at

    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.

  • Verified answer
    murali Profile Picture
    Microsoft Employee on at

    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(....)})

  • Meneghino Profile Picture
    6,949 on at

    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 Profile Picture
    356 on at

    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.

  • murali Profile Picture
    Microsoft Employee on at

    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 Profile Picture
    6,949 on at

    @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 Profile Picture
    356 on at

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

  • vsslasd Profile Picture
    349 on at

    Thank you, All. 

    Also wish there was additional/better documentation on this. 

    The UpdateContext isn't what I am looking for as much as updating the actual Collection itself. 

    How is that done? I don't think it is automatic, is it, unless one does a forced refresh: Refresh(Collection, SQLTable) ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard