I have this function in my canvas app and on button clicked I am patching my collection in Dataverse table Order and Order details. My col name is Product for check. I have loading spinner when button clicked that disables screen, I have IsPatchingInProgress that disables the button. I also empty collection after Patch. The problem is that sometimes this functions creates 2 duplicate order and sometimes even 4 duplicate orders. Do you know how is this possible.
Set(
LoadingSpinnerVisibilty,
true
);
Set(IsPatchInProgress, true);
Set(
CurrentOrder,
Patch(
'Order',
Defaults('Order'),
{
Company: CurrentUser.'Business Unit',
Customer: SelectedCustomer,
'Total value': Sum(ProductsForCheck,Sum(totalvalue)),
Delivery:drpDelivery.Selected.Value,
'Customer Text':SelectedCustomer.'Account Name',
'Customer Reference':varcustref
}
)
);
ForAll(
ProductsForCheck,
Patch(
'Order Details',
{
'Product Name': productname,
'Product Number': productNo,
Quantity: Value(quantity)
}
)
);
Reset(ComboBox1);
Set(
resetCustomer,
true
);
Set(
resetSearch,
true
);
Set(
LoadingSpinnerVisibilty,
false
);
Notify("Order successfully submitted",NotificationType.Success);
Set(IsPatchInProgress, false);
If(
CountRows(Filter(ProductsForCheck, Value(additionaldiscount) > 0)) > 0,
Set(showDiscountNotificationPopup,true),
Clear(ProductsForCheck); Reset(txtSearchCustomer); Set(SelectedCustomer,Blank())
)