Hi, I'm trying to get my scan property to add to the quantity of the scanned item if it is scanned multiple times, instead of adding more entries.
I have a basic app (has to be simple) where users can scan products to perform an inventory count (its only purpose) The scanned records are stored in a collection with other data like date, user, location, quantity. But if the item is scanned again, it is added as another entry. How can it be done so that if the record has already been scanned, only the quantity is updated without it being added as new and if it has not been scanned, it is added as new?
The line of code is always and basic:
Thanks for the observation, an error that I have noticed in the application is that there comes a time when the scan does a double capture at the same time and closes the application unexpectedly, this implies losing the captured record, I think adding a DataSave function local before sending the data would protect against failure. I still don't know if this failure is from the app or from the computer where the app is running.
Thank you very much for the support and comment.
My apologies. I overlooked this yesterday but since we already collect the barcode value within the colScannedItems and search for the duplicate record within the With function: are Barcode1 and CurrentRecord still required?
In case the variables are not used elsewhere within the app, they can be removed. Should CurrentRecord be required - we can simplify my previous code as the With function will be redundant.
I hope this helps!
Thanks for the notes and solution.
The variable: "Set(Barcode1;First(BarcodeReader1.Barcodes).Value;;"
Do I put it in onStar of the app or can I leave it onscan?
Hi @Ktrujillo,
The code below will update the quantity by 1 in case a record with the same 'ScannedItem' value exists - otherwise it will add a new record to the collection. I have added inline comments to further explain the code.
Set(Barcode1;First(BarcodeReader1.Barcodes).Value;;
Set(CurrentRecord;LookUp(colScannedItems;Barcode1=ScannedItem;ThisRecord));;
With(
{
//Search for the current scanned item & save to a record scope variable
wRecord: LookUp(
colScannedItems;
//If additional fields have to match, please add them combined with the and operator &&
ScannedItem = First(BarcodeReader1.Barcodes).Value
)
};
If(
//If it exists update quantity, else create a new record
!IsBlank(wRecord);
Patch(
colScannedItems;
wRecord;
//Add 1 to existing Qty
{Qty: wRecord.Qty + 1}
);
Collect(
colScannedItems;
{
ScannedItem: First(BarcodeReader1.Barcodes).Value;
Qty:"1";
Location:"";
ScannedTime: Now();
Registered:User().FullName
}
)
)
)
If this solves your question, would you be so kind as to accept it as a solution. ✔️
If you liked my solution, please give it a thumbs up. 👍
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional