12 - Enable App to Select Product by Scanning Barcode
Show some of the native mobile capabilities of SAP Build Apps by allowing users to select a product by scanning a barcode, as part of the SAP Build CodeJam.
Overview
You will learn
- How to get and set up the Mobile Preview App
- How to enable barcode scanning
Prerequisites
Prerequisites
- You have completed the previous tutorial for the SAP Build CodeJam, Add Rework Flow to Your Process.
Steps
To get and set up the SAP Build Apps Mobile Preview App, watch and follow along with this video from Daniel Wroblewski.
Go to the home page.
Select User Interface.

Back home Right now, you have a title component.

UI title Add a Row component just above the title.
When you drag in a row component, it will automatically contain 2 cells.

Add row Move the existing title component into Cell #1.

Move title In Cell #2, add a container, and in the container add a text and icon component.
The UI should look like this:

New UI Select the row component (use the tree view), and in the Layout tab click the first 50%.

Alt text Set the cell width to
5.
Cell width Now click the other side, now 0%, and then enter for the cell width
3.
Cell width, again This now sets the relative widths of the cells.

Row widths Finally, set Align cell content to align bottoms.
Select the container in Cell #2, and in the Layout tab, in the Layout section, set the layout to Horizontal.

Container layout Select the text component (in Cell #2) and set the following.
Under Properties, set Content to
Click to scan product.
Text In the Style tab, click the Primary Paragraph dropdown, and click Edit.

Edit style Under Typography, set Text size to Small text.
In the Layout tab, in the Layout section, change Text align to right.
Select the icon component (the star in Cell #2), and set the following.
Under Properties, in the Icon property, click the word star.

Select star Enter
barcodein the search, and click the barcode symbol.
Icon Under Style, click the Primary Icon dropdown, and click Edit.

Style edit Under Typography, change the binding type for Font size to Static number, and change the font size to
60.
Your UI should now look like this:

Now lets create the logic for handling the tap of the barcode icon.
Select the icon component, open the logic canvas (at the bottom).

Open icon logic Create the following logic, and connect the flow functions as shown.

Basic logic The logic opens the barcode scanner, and if the user actually selects a barcode, then you test that value.
If the value is a product number and in our list of products – held in our data variable – then you navigate to the product details page.
If the value is not a product, you just alert the user.
IMPORTANT: You must connect the top output of he QR code flow function with the If condition flow function.
For the If condition flow function, set the Condition to the following formula:
JavaScriptIS_IN_ARRAY_BY_KEY(data.Products1, "Id",outputs["Scan QR/barcode"].codeContent)For the Open page flow function, set the Page to Product Details.

Open product details Set the productID to the Output value of another node > Scan QR/barcode > QR barcode content.
For the Alert flow function, set Dialog title to the following formula:
JavaScript"No such product " + outputs["Scan QR/barcode"].codeContent
The logic should now look like this:

Now you will use the mobile preview app so you can use the native functionality of the device.
Make sure you have installed the preview app on your device.
Click Preview.

Open launch tab You should get a page like this:

QR code Open the preview app on your device.
Click Scan Login QR Code.
]
Click Scan Scan the QR code on your preview page.
]
Scan This should give you a 6-character code.
]
Pin code Take the code and enter it in the preview page in SAP Build Apps.
Press Enter (or click Confirm Pin).
The pin code can be entered upper or lower case, and you can press Enter instead of clicking Confirm pin.

Enter code If all goes as planned, you will see that you have been authenticated.

Authenticated Your preview app will now update and show all the applications in your tenant. You should see something like this:
Preview app authenticated Click the Shopping App tile to open the app.
Click the barcode icon.
Barcode icon You can scan this barcode for product HT-1020.

HT-1020 This should take you to the product details page, where you should see the details for HT-1020.
Product details
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.