How to create a barcode scanner in Power Apps / Power Platform
This tutorial shows how to create a barcode scanner in Power Apps / Power Platform that uses the phone camera to read codes and write results to SharePoint or Dataverse — useful for inventory, asset registration or quick scanning. I will explain the reasons for the choices and provide a practical step-by-step, including handling common errors.
Prerequisites
- Account with a Power Apps license and access to create Canvas Apps.
- A SharePoint site with a list or a Dataverse environment (choose where to store the records).
- Phone with a camera and the Power Apps app installed to test the scanner.
Step 1: Create the list in SharePoint (or table in Dataverse)
We need a place to store the read data. If you choose SharePoint, create a list with simple columns: Title (unique), BarcodeText, DataHora, Observações. In Dataverse create a table with equivalent columns.
Step 2: Create a blank Canvas App
Create a Canvas App (Phone layout) in Power Apps Studio. The Phone layout makes camera use easier. Name the app 'ScannerBarcodeApp' for easy identification.
Step 3: Add the scanner camera
Use the built-in BarcodeScanner control. This control simplifies reading 1D and 2D codes without external libraries.
Inserir > Media > BarcodeScanner
Set essential properties: OnScan to handle the result and Visible to control when to show the scanner.
Step 4: Save the result to the data source
Add the connection to the SharePoint list (or Dataverse). Then use the Patch or Collect function in the BarcodeScanner OnScan event to write. Explanation: Patch allows creating a new record and returns errors; Collect creates without immediate feedback.
// Exemplo usando Patch para SharePoint
OnScan =
If(
!IsBlank(BarcodeScanner1.Value),
Patch(
'ListaInventario',
Defaults('ListaInventario'),
{
Title: BarcodeScanner1.Value,
BarcodeText: BarcodeScanner1.Value,
DataHora: Now(),
Observações: "Lido via BarcodeScanner"
}
);
Notify("Código gravado com sucesso", NotificationType.Success),
Notify("Erro ao ler ou gravar o código", NotificationType.Error)
)
Step 5: Show feedback and prevent duplicate reads
It is common for the scanner to read the same code multiple times. Use a variable for debouncing and a duplicate check before saving.
// Variável para evitar leituras rápidas em OnScan
Set(varLastScan, BarcodeScanner1.Value);
Set(varScanTime, Now());
// Verificar duplicado (exemplo SharePoint)
If(
CountRows(Filter('ListaInventario', BarcodeText = varLastScan)) = 0,
// Guardar
Patch('ListaInventario', Defaults('ListaInventario'), { Title: varLastScan, BarcodeText: varLastScan, DataHora: Now() }),
Notify("Código já existe", NotificationType.Information)
)
Step 6: Handle errors and improve the experience
Handle common scenarios: no camera permission, unreadable code, or network issues. Use IfError, Notify and check permissions with App.IsDevicePermissionGranted('Camera').
// Exemplo de verificação de permissão antes de mostrar scanner
If(
App.IsDevicePermissionGranted("Camera"),
Set(varShowScanner, true),
RequestDevicePermissions("Camera")
)
// Exemplo simples de tratamento de erro no Patch
IfError(
Patch('ListaInventario', Defaults('ListaInventario'), { Title: varLastScan, BarcodeText: varLastScan, DataHora: Now() }),
Notify("Falha ao gravar. Tenta novamente.", NotificationType.Error)
)
Verify the result
Test in the Power Apps mobile app: open the app on the phone, allow camera access, scan a code and confirm the record appears in the SharePoint list (or Dataverse table). Check the Notify messages and confirm duplicates are prevented. Common errors: camera blocked, different list name, or missing columns — adjust the names in the formulas.
Conclusion
You now have a functional barcode scanner in Power Apps / Power Platform that writes to SharePoint or Dataverse and handles duplicates and permissions. Next steps: add code type identification (QR vs EAN), fetch external information via Custom Connector, or display the product image after scanning. Tip: test under different lighting conditions to improve read rate — what will be the next field you want to automate in inventory?