Hey all, beating my head against the wall trying to fix this issue with our charitable product request app and thought I'd throw a Hail Mary and hope someone might see something I'm missing or have a fix! It's a bit complicated so sorry for the long post, but there's probably an easier way to do this or something I'm not doing right.
It should be pretty simple:
1) They fill out a form;
2) They add products to this form (it uses a ComboBox to lookup the codes and fill in the item name, quanity, and warehouse);
3) The data is managed in a collection/gallery for viewing and for our patch to Sharepoint.
If we just add the items and fill it in and submit, everything is good. But if they have 5 products added for example, then change one of them, the other boxes seem to randomly change and duplicate or even change to a separate code somehow -- this GIF is a bit long too but will show how sometimes it's fine, other times it randomly changes?
The goal of our PowerApps screen is to create a "New Product Request" form that allows users to add multiple products to a request, fill out necessary details, and submit the form. Each product is represented as a row in a gallery, and users can update specific details for each product. The final data is submitted to a SharePoint list.
Initialization of Data:
Adding New Products:
Updating Product Details:
Submitting the Form:
1. Initialization
When the screen loads, we clear any existing data in the collection and reset the main form. We also initialize a request number and set up the ProductCollection with a default item. The initialization code is as follows:
// OnVisible property of the screen
Clear(ProductCollection);
ResetForm(Form4);
Set(RequestCounter, RequestCounter + 1);
Set(RequestNumber, "PR" & Text(RequestCounter, "000"));
Set(NextItemID, 1);
Collect(ProductCollection, {
ItemID: NextItemID,
RequestNumber: RequestNumber,
ProductType: "",
ItemName: "",
ItemCode: "",
WarehouseCode: "",
CaseQuantity: 0
});
Purpose:
2. Adding New Products
When the "Add Products" button is clicked, the item number is incremented, and a new product row is added to the ProductCollection with default values. The code for adding new products is:
// OnSelect property of AddProductsBTN
Notify("Please Add Products.", NotificationType.Information);
Set(NextItemID, NextItemID + 1);
Collect(ProductCollection, {
ItemID: NextItemID,
RequestNumber: RequestNumber,
ProductType: "",
ItemName: "",
ItemCode: "",
WarehouseCode: "",
CaseQuantity: 0
});
Notify("New product row added to collection.", NotificationType.Success);
Purpose:
Updating Product Details
Users can update product details using various input controls within the gallery. For instance, when the ComboBoxItemCode_1 changes, the product details are updated in the collection. The code for updating product details is:
// OnChange property of ComboBoxItemCode_1
Patch(
ProductCollection,
LookUp(ProductCollection, ItemID = ThisItem.ItemID),
{
ItemCode: Self.Selected.Title,
ItemName: LookUp(dstOffering, Title = Self.Selected.Title, 'Item Name'),
ProductType: LookUp(dstOffering, Title = Self.Selected.Title, 'Dp Type'),
WarehouseCode: LookUp(dstOffering, Title = Self.Selected.Title, 'Warehouse Code')
}
);
Notify("Product details updated.", NotificationType.Information);
Purpose:
When the CaseQuantityInput_1 changes, the quantity is updated:
// OnChange property of CaseQuantityInput_1
Patch(
ProductCollection,
LookUp(ProductCollection, ItemID = ThisItem.ItemID),
{ CaseQuantity: Value(Self.Text) }
);
Notify("Case Quantity updated.", NotificationType.Information);
Purpose:
Controls in the Gallery:
ComboBoxItemCode_1:
ItemNameInput_1 (Read-Only):
ProductTypeInput_1 (Read-Only):
WarehouseCodeInput_1 (Read-Only):
CaseQuantityInput_1:
Using CountRows:
Using GUIDs:
Using Global Variables:
ForAll:
Jay2814, that fixed it! Thanks so much for reading through my long post and helping with the issue. Now I just wish I posted earlier so I could better understand how a gallery actually works and why my method was wrong.
Appreciate your help and for explaining the issue to me.
Hi KBpwr,
It might be because of your OnChange property for ComboBoxItemCode_1. Since galleries duplicate the same element for all items in the gallery, it is creating a conflict and is applying the patch for the other products.
For example, you may be intending to only patch product ID 1 but since the element ComboBoxItemCode_1 is technically the same for all of the other products, it is also patching products ID 2 and 3 with the changes from product ID 1.
Possible Solution:
On the On Select property for ComboBoxItemCode_1 you can create some sort of variable to track the actual ID of the product you are intending on modifying:
//On Select
Set(parentID, ThisItem.ID);
Then in your On Change property, slightly modify your code as the following to only patch that specific record:
// OnChange property of ComboBoxItemCode_1
If(parentID=ThisItem.ID), Patch(
ProductCollection,
LookUp(ProductCollection, ItemID = ThisItem.ItemID),
{
ItemCode: Self.Selected.Title,
ItemName: LookUp(dstOffering, Title = Self.Selected.Title, 'Item Name'),
ProductType: LookUp(dstOffering, Title = Self.Selected.Title, 'Dp Type'),
WarehouseCode: LookUp(dstOffering, Title = Self.Selected.Title, 'Warehouse Code')
}
));
Notify("Product details updated.", NotificationType.Information);
Let me know how this works out for you.
Thank You.
WarrenBelz
110
Most Valuable Professional
MS.Ragavendar
77
stampcoin
52