Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building 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}
)

 

 

  • Ktrujillo Profile Picture
    10 on at
    Re: Barcode scanner and update the record if a collection is already scanned

    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.

     

  • LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Barcode scanner and update the record if a collection is already scanned

    @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
    Re: Barcode scanner and update the record if a collection is already scanned

    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?

  • Verified answer
    LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Barcode scanner and update the record if a collection is already scanned

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard