cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SF1173NYC_TX
Frequent Visitor

Values Reset in Dropdown/ComboBox fields when you edit form.

I have a powerapp that is connected to two sharepoint lists.  One where the data of the form gets sent to and the other that provides the values to 2 dropdowns and 1 combo box.  It works when the form is created however when you go to edit the form all the fields get reset to the first value in the list.  I have tried many ways to solve this but so far I have not been successful so hoping someone can help me here.  Basically I have a State Field, Market Type and Legal Entity that came from the sharepoint list fields that cascade info based on the state selection.  In powerapps I added 1 dropdown for State, a combobox for Market Type and another dropdown for Legal Entity I have the Items for each field programmed as follows:

SF1173NYC_TX_0-1615310673073.png

SF1173NYC_TX_1-1615310738459.png

SF1173NYC_TX_2-1615310794345.png

To get the data back to the fields that will go back to the sharepoint list I updated the Default and Update for each as follows:

State Default-SF1173NYC_TX_3-1615311056044.png State Update-SF1173NYC_TX_6-1615311156621.png

Market Type Default-SF1173NYC_TX_4-1615311077275.pngMarket Type Update-SF1173NYC_TX_7-1615311225270.png

Legal Entity Default-SF1173NYC_TX_5-1615311095907.pngLegal Entity Update-SF1173NYC_TX_8-1615311299594.png

 

Any ideas what I am missing as I can't figure out how to solve this issue.

 

 

 

 

8 REPLIES 8
TheSec
Helper I
Helper I

Hello,

 

not sure if I understand the issue correctly so I just describe how I handle these scenarios.

When you have a main table and a child table you habe to build a relationship between them.

 

For the main table I create a variable on load where I store the record.

For the child table I create a variable with the relationship like 

 

Filter(ChildTable; ID = varMainTable.ID)

So you have two variables containing your current record und your dropdowns should be filled.

Without this connection you have to set your fields manually. By this way you can simply user the varTable.field or even thisItem.Field depending on the design.

By this way you can also build a combination with one form and one gallery e.g. with the customer data on the top and the list of invoices below on one screen.

 

Edit: Screenshot for explanation

I wasn't able to see anything in your screenshot however, I was able to solve the issue with the two dropdown by setting the Default to SharepointIntegration.Selected.ColumnName but still need to solution the combobox as that same formula didn't work there. 

Screenshot is empty or not understandable?

SF1173NYC_TX
Frequent Visitor

Sorry but my issue has not been solved.  I have a combo box connected to a data source coming from a share point list and it works fine when a new form is created but if I go back and edit that same form in the sharepoint list the values go away.  I need the values the user selected initially to still be selected in the form and so far everything I have tried doesn’t work.  I’m not using any galleries

I'm under pressure. I will prepare an example as soon as possible. 

TheSec
Helper I
Helper I

Hello SF1173NYC_TX,

 

Welly from Microsoft took the time to help me with a Customer voice problem, so it’s time to try to help you.

 

Your issue is that your form only works with new data, but doesn’t properly fetch existing rows.

 

This can be caused by different issues.

 

PowerApps has three types of forms: new, edit, view.

 

So when you use a form with display mode „new“ it always creates a new record. Your fields are empty.

When you want to show an existing record your form has to be in view or edit mode.

 

The according property is called DefaultMode and it can also be set by code using variables.

By this way you can have one form for all three modes. 

 

I write this so you can understand better my code where I pass the varFormMode variable with the navigate command. And when I create a new record I have to do a reset form to insure the  form isn’t linked to a record and is empty or the variable is newly loaded.

 

The following code snippets are from an app that is managing meetings with connected agenda items in two linked SP lists. Meeting in German = Sitzung and agent item = Tagesordnungspunkt.

 

 

The code for a new Sitzung:

 

/* clearing the form */

ResetForm([@FormSitzung]);;

 

/* creating a new variable holding the to create record, Defaults is for a new empty record with the predefined selection and default values of the SP List */

 

Set(varFormData;Defaults(Sitzung));;

 

/* Setting the form mode to edit */

Set(varFormMode;FormMode.Edit);;

 

/* now navigating = open the form with the new empty record connected to the variable */

 

Navigate(ScreenSitzung)

 

To open a selected record e.g. from a gallery I do the following in the on select property of the Gallery:

 

ResetForm(FormSitzung);;

Set(varFormData;ThisItem);; /* this item is automatically the SP record currently selected in the gallery */

Set(varFormMode;FormMode.Edit);;

Navigate(ScreenSitzung)

 

Now to the connected table with the Tagesordnungspunkte (1:n relationship).

 

Because I have the Sitzung in the variable I can easily build the relationship this way:

 

Filter(Tagesordnungspunkt;SitzungID = varFormData.ID)

 

This is the simple code for the items property of the gallery to show the connected rows of the other table.

I create a new connected record this way:

 

ResetForm(FormTagesordnungspunkt);;

/* write new record into a new empty variable and save the connection ID in the new variable with patch*/

 

Set(varSubFormData;Patch(Defaults(Tagesordnungspunkt);{SitzungID: Value(ID_SitzungValue_2.Text) }));;

 

Set(varSubFormMode;FormMode.Edit);;

 

Navigate(ScreenTagesordnungspunkt) 

 

Now I have the current „master“ record (varFormData) and the „child“ record (varSubFormData) both in variables at the same time and can work on both and save both in the same time or independently from each other.

There is no limit for connections between tables, but you should keep in mind that relationship IDs should be saved as number in the SP list. Using text columns can break your data integrity.

 

You can have multiple forms and galleries in one screen this way.

It’s just up to you to save the variables the right way to the SP list.

 

My preferred way to save the data is patch like this:

 

Patch(Sitzung;varFormData;FormSitzung.Updates);;

Refresh(Sitzung) 

 

Where Sitzung is the SP list und form.Updates just saves the changed fields in the form held by the variable to the datastore.

 

 When you have multiple forms and tables connected you just do a patch for every form / table.

 

 

Patch(Sitzung;varFormData;FormSitzung.Updates);;

Patch(Tagesordnungspunkt;varSubFormData;FormTagesordnungspunkt.Updates);;

 

Loading records in variables also seems to have the best performance.

 

I hope I did an OK job in explaining. If not, I will try to clarify this with some screenshots and drawings.

reedbg
Advocate I
Advocate I

ComboBox1.SelectedItems returns a table instead of a single record.  If your ComboBox is single select, you can use using ComboBox1.Selected or First(ComboBox1.SelectedItems).

Thanks @reedbg its a multi select combo box.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,105)