Featured image of post Displaying Newly Created Record After Saving in a Canvas Power App Form Control

Displaying Newly Created Record After Saving in a Canvas Power App Form Control

Canvas app development in Power Apps is pretty fun. Having the ability to not only fine-tune your interface but also connect to a wide variety of data sources makes it an essential tool to turn to these days. Indeed, if you still find yourself working with Access databases, I would push you to at least look at what canvas Power Apps can do for you and your organisation. I’d also encourage longstanding Dynamics CRM / Dynamics 365 developers to familiarise themselves with canvas apps although, as the example in this post will demonstrate, attempting to figure out some of their…unique oddities can sometimes be an exasperating process.

There may be occasions within a canvas Power App form control¬†where any newly created record should be displayed back to the user, using the same form control. Unfortunately, by default, it’s not possible to quickly implement this behaviour. When, for example, the user presses a button that calls the¬†SubmitForm function, any data entered will be successfully saved into your target system, and the user will see a blank screen instead of the new record. This behaviour occurs because, as outlined in the documentation, the controls FormMode property updates automatically to Edit as opposed to New when you call the SubmitForm function. While this all sounds well and good, unless you have specifically¬†told the form control which record you would like to render, we default instead to the behaviour outlined earlier. Not ideal! ‚ėĻ

To fix this issue, there are a few things we can do, all of which involves the creation of some additional expressions to achieve successfully. It also requires us to become familiar with a specific function type called UpdateContext, which is your gateway into using context variables. These are a particular kind of variable that is scoped to the current screen only and is automatically disposed of when the user navigates away. In the circumstances relating to the current requirement, therefore, context variables make the most logical sense to use. And, when used in conjunction with the form controls LastSubmit property, allows to us capture and re-use details regarding the last successfully submitted record elsewhere on our Power Apps screen. We will use both of these features as part of the first step of the solution.

Navigate to the OnSuccess property of your form control, and add in the following expression - replace the fm_MyForm portion with the actual name of your form:

UpdateContext({varLastSubmit: fm_MyForm.LastSubmit});

Now, we can store details of each successfully created record including, most importantly, its identifier.

Next, on the same form control, navigate to the Item property and enter the following value:


And that’s it - whenever you now call the SubmitForm button, the newly created record will render correctly, due to the following conditions now being met:

  • The form mode equals Edit
  • An applicable¬†Item record value exists for the form control.

Just always make sure that the form mode is changed to New by default whenever a user navigates to the screen containing the form for the first time. Using the following expression(s) will sort this all out for you, navigating the user to the FormScreen screen and updating the forms mode accordingly:


This particular behaviour is something that, for first time Power Apps developers, can take a little bit of time to grasp fully. Once you fully understand (i.e. RTFM) the behaviour of form controls, you can start to understand why these extra steps are required. Hopefully, if you’ve been scratching your head over this particular quirk, then this post will help you along ūüôā

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy