cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Controls inside the Gallery getting reset after patch

 The goal of this app is users is entering inventory. User will select a product and quantity and hit the save button which should show another line where the user will repeat entering the product and quantity and finally  hit a save button that then writes all the captured data into SP list. Because the number of products might vary anywhere from 1 to 100, it should be dynamic, and the user should be able to add how many records they want depending on the number of products. Like how Shawn Young showed in this video. https://www.youtube.com/watch?v=HUX_0AA4-Hs

        So, to achieve this I have tried to do the following steps but I am kind of hitting the wall with the data in the gallery getting reset. Here is what I did:

  • Add a Screen
  • Set On Visible property to load data into colItems (has a list of products) and colData(where the data is saved to)

 

 

 

ClearCollect(colItems,["A","B","C"]);
ClearCollect(colData,{Product: "",Qty: 0});

 

 

 

1.jpg

 

 

 

3)Add a Gallery and set Items property to ColData.

4) Add a ComboBox, a Text Input and a save icon.

 

 

 

 

 

5) Set Items property on ComboBox to ColItems.
6) Set Select Multiple property to false.

3.jpg

 

 

 

 

 

 

 

 

7) On the save button add a patch to collect the data into ColData and also add a collect statement into colData to add a blank row.

 

 

 

 

Patch(colData,ThisItem,{Product: ComboBox2.Selected.Value,Qty: Value(TextInput2.Text)});
Collect(colData,{Product: "",Qty: 0});

 

 

 

8 - Everything works well until here. Except, once I select a product from the combobox, enter a quantity and hit save, the value in the combobox and textinput gets reset to blank like shown below:

 4.jpg

 

 

 

 

 

 

 

When I check the data in colData, the data entered is very much in it. It just doesn’t show up in the gallery for some reason. This is what I am unable to figure out.

5.jpg

 

 

 

 

 

 

I know that it might because the Items property on the Gallery is ColData and the patch I have on the gallery also writes (Patch) to ColData and that is probably why this issue is happening but I am not sure how to solve it. Is it something to do with the Default property of the combobox? I have tried this as Default and DefaultSelectedItems but none of them worked.

I am not even sure if I need a default value because the selections are showing up just fine in the combobox.

 

 

 

First(Filter(colData,Product=ThisItem.Product))

 

 

 

Please let me know what I need to change here to make it work. Thanks in advance for any inputs/ direction.

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @testtest123test ,

Do you mean that:

1)combo box's Items is colItems collection?

2)you want the combo box to display the value of Product field in colData collection?

If so, the reason why you use "First(Filter(colData,Product=ThisItem.Product))" can not work, is not the defaultselecteditems and items should belong to the same table. If you set like that, its Items data source is colItems collection, its defaultselecteditems data source is colData.

 

Please set like this:
1)combo box's Items:

colItems

2)combo box's DefaultSelectedItems:

Filter(colItems,Value=ThisItem.Project)

3)textinput's Default:

ThisItem.Qty

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
WarrenBelz
Super User
Super User

Hi @testtest123test ,

This is a well-documented bug - I see you are Patching to a collection, which makes this a bit easier.

In your Collection code, add AddColumns for the field/s you want to see (happy to help if you give me the collect code and the control names) then Patch also to these fields. You then make the Default of the affected controls these field names, so when you Patch and the gallery refreshes, the control will reflect the value previously in it.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

 

Hi @WarrenBelz ,

 

Thanks for blazing quick reply. 

 

Are you referring to the collect code for colItems? It is just ClearCollect(colItems,ShowColumns(Items,"Title")) instead of static A,B,C i posted in my original post.

 

 My combo box name is ComboBox2 and TextInput name is TextInput2.

 

Any link that I can read further?

Thanks again!!

Hi @testtest123test ,

Using your names, your collection could be something like

ClearCollect(
   colItems,
   AddColumns(
      ShowColumns(
         Items,
         "Title"
      ),
      "ComboShow",
      "",
      "TextShow",
      ""
   )
) 

The dummy field names do not matter - you just need to Patch to them as well when Patching to Title, then have the Default of the Text Input to ThisItem.TextShow and the ComboBox to ThisItem.ComboShow. That way, they will show the values that were in them before.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

v-yutliu-msft
Community Support
Community Support

Hi @testtest123test ,

Do you mean that:

1)combo box's Items is colItems collection?

2)you want the combo box to display the value of Product field in colData collection?

If so, the reason why you use "First(Filter(colData,Product=ThisItem.Product))" can not work, is not the defaultselecteditems and items should belong to the same table. If you set like that, its Items data source is colItems collection, its defaultselecteditems data source is colData.

 

Please set like this:
1)combo box's Items:

colItems

2)combo box's DefaultSelectedItems:

Filter(colItems,Value=ThisItem.Project)

3)textinput's Default:

ThisItem.Qty

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@testtest123test , 

@v-yutliu-msft 's response seems to be on a different issue to what I deduced from your post.

Is it the gallery refresh (when not required) that is the issue for you as this is what I have addressed?

JR-BejeweledOne
Super User
Super User

Make sure that your Combobox and text input box 'Default' property is set to the matching ThisItem.xxxx that is in your collection.

Here is an example.

 

My gallery is set to the collection Markets.   Markets has 3 columns (Region, Country, Country Code).   Here is the screenshot:

 

gallery.png

 

For each control in the gallery, the Default property is set to ThisItem.xxx.  Here is the setting for the Region control.

 

ThisItem.png

 

Also I set the DisplayMode to Display once the item has been patched.  ShowSave is a variable that is set to true or false for the individual record in the collection.  It can be used to set the visible property of your Save icon and in other places as well such as below.

 

If(ThisItem.ShowSave = false, DisplayMode.View, DisplayMode.Edit)

 

This prevents the saved item from being blank.

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Worked like charm. Thanks a lot.

Hi @JR-BejeweledOne ,

 

Thanks for your reply. ThisItem.XXX worked for the text input but for combobox, it didnt. What v-yutliu-msft mentioned, I have used 

Filter(colItems,Value=ThisItem.Product)

as combox's DefaultSelectedItems and ThisItem.Qty as Default of TextInput and it worked perfectly.

 

Thank You.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,852)