web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Barcode scanner and up...
Power Apps
Answered

Barcode scanner and update the record if a collection is already scanned

(1) ShareShare
ReportReport
Posted on by 10

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:

 

Set(Barcode1;First(BarcodeReader1.Barcodes).Value;;
Set(CurrentRecord;LookUp(colScannedItems;Barcode1=ScannedItem;ThisRecord));;
Collect(
    colScannedItems;
    {ScannedItem: First(BarcodeReader1.Barcodes).Value;Qty:"1";Location:"";ScannedTime: Now();Registered:User().FullName}
)

 

 

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    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👍

     

    Connect with me: LinkedIn | Blog

  • Ktrujillo Profile Picture
    10 on at

    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?

  • LaurensM Profile Picture
    12,516 Moderator on at

    @Ktrujillo,

     

    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!

  • Ktrujillo Profile Picture
    10 on at

    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.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,033

#2
Valantis Profile Picture

Valantis 632

#3
11manish Profile Picture

11manish 607

Last 30 days Overall leaderboard