cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
winj945
Helper I
Helper I

Prepopulate New Form Based on Selected Item in Gallery

Hi everyone,

I created a Canvas App which works as follows: lets assume I have two screens, one NavigationScreen and one NewFormScreen.

On the NavigationScreen there is a Gallery1, which contains order head information (order date, product name etc.; SQL table). Now i want that this information is grabbed and used to prepopulate some fields of the NewForm of the NewFormScreen. After the user added further information he submits the NewForm to a sharepoint List. So he creates a new record in the sharepoint list, which contains the head information of the selected records of Gallery1 and the added information by the user. I solved this by referencing the Gallery1 fields in the default property of the NewForm like this:

NewForm.Datacard1.Default = Gallery1.Selected.Column1

This works. However, I have like 10 NewForm Screens, which all reference the Gallery1 records. I published the app, tried it on a tablet and had big performance issues. I assume, that PowerApps has a problem with the reference, so that it has to load several Screens at a time. So my question is: Is there a more performant way to prepopulate my NewForm fields?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

I'm making lots of assumptions about your app, so feel free to tell me I'm wrong 😉

 

I would put the ClearCollect statement immediately before the Navigate(), in the same button if that's what you are using. A collection is like a global variable, so you don't have to fuss with passing it through the Navigate function itself. The ClearCollect should be as simple as you need:

ClearCollect(colFormDefaults,
{
    Title: Gallery1.Selected.Title,
    ItemName: Gallery1.Selected.ItemName,
// And so on, to have only the records you need for your defaults
)

 

Access these values again using syntax like this:

First(colFormDefaults).Title // Brings up the value stored in the Title field of the first and only record in colFormDefaults
_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
BCLS776
Super User
Super User

As you Navigate() to your NewFormScreen, put the Gallery1.Selected record into a collection with only the columns you need for pre-populating your form. Then, use the Default properties as before, but refer them to the new collection. This will keep Power Apps from generating multiple queries to the data source of your gallery, which is likely external to your app.

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Thank you @BCLS776 for the quick answer. The Idea is really good, but how do i realize this? I have difficulties where to put the ClearCollect and if I pass the Gallery1.Selected as the third argument of the navigate() it does not return any values, your empty columns ...

I'm making lots of assumptions about your app, so feel free to tell me I'm wrong 😉

 

I would put the ClearCollect statement immediately before the Navigate(), in the same button if that's what you are using. A collection is like a global variable, so you don't have to fuss with passing it through the Navigate function itself. The ClearCollect should be as simple as you need:

ClearCollect(colFormDefaults,
{
    Title: Gallery1.Selected.Title,
    ItemName: Gallery1.Selected.ItemName,
// And so on, to have only the records you need for your defaults
)

 

Access these values again using syntax like this:

First(colFormDefaults).Title // Brings up the value stored in the Title field of the first and only record in colFormDefaults
_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Hey @BCLS776 , your assumptions are correct so no need to intervene 😉 However, I tried your approach and it works perfectly for new forms. But what about edit forms? So after the user has created the new record (with the head info) and he wants to update values, he picks the records from another gallery and feeds it into an edit form. Is there a way to also put the selected record in a collection to avoid referencing the previous screen? The edit form is complaining and expects a data source rather than a collection ... I'm confused that powerapps is complaining about referencing controls in previous screens, because it seems that picking a record from a gallery and navigating to an edit screen (hence referencing the previous screen) seems the absolut default approach ...

You've got a few questions there, so I'll try to address as many of those as I can 🙂

 

  • Any form control should point to the external data source it is expected to save into. You can populate the cards' values in lots of ways (user input, other controls, calculations), but there's only one place to save the form data
  • If you have another gallery you want to access, do it the same way as you did for the first one, using a gallery.Selected reference (and maybe store it in a collection)
  • An Edit Form is simply a form that has been toggled into an editing mode, but it needs to know which record from your external data source you are trying to change. If there is a record already loaded, calling EditForm() will allow you to edit the values for that record. Many apps let a user select a record through a gallery, and then use the .Selected notation to reference the specific record to bring up in the Edit Form.
  • Power Apps shouldn't complain about referencing controls from another page. Controls are a handy way of accessing data throughout your app and they are uniquely identified.

Does that help?

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.
winj945
Helper I
Helper I

I really appreciate your input! And yes, it helps to understand my problem better. I see it that way too, that Power Apps shouldn't complain about referencing controls from another page (I understand it to an even lesser extent, as I'm pointing to a gallery on a previous screen, which should always be already loaded, right?). However, Power Apps warns me about "inefficient delay loading" because of those references. I think I will keep those references in a first step and optimize performance by means of other changes in the app design.

 

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,369)