SAP Screen Personas
Create: Vandana Deep Feb 13, 2018 22:11
Last Update: Regina Sheynblat Feb 05, 2019 23:54
Scripting: Building flavors with Barcode scanning functionalitySAP SCREEN PERSONAS KNOWLEDGE BASE - by Vandana Deep , Regina Sheynblat
In SAP Screen Personas 3.0 SP06, we introduced the SAP Screen Personas Slipstream Engine. One of the biggest advantages of Slipstream Engine is that it allows for the creation of flavors that can run on mobile devices.
We are often asked how a user can access native device capabilities, such as a camera, GPS, calendar, or contacts from within their flavors.
This article describes how we can access a device’s camera and use it to read a barcode with a simple script.
Barcode scanning script
Let’s use the example of a sales order dashboard, where the user scans a barcode for a material to get more details on the material number.
As mentioned previously, we will accept the user input using the phone camera for scanning the barcode.
Once the material is selected (the barcode is scanned), the user can click on the Check Material Details button to launch transaction MM03. This will pre-populate the transaction with the material number scanned earlier.
Let's take a look at the script we need to create for the Scan button.
OnScan script does the following:
- Checks if the variable - Cordova is defined, which is only in the case where the Slipstream engine flavor is running in the Fiori Client app.
- if defined, it calls the scan method for the barcodeScanner object which expects the following 2 inputs:
- Success callback function (in our case scanSuccessCallback())
- Failure callback function (in our case scanErrorCallback())
The Cordova API is using callbacks to notify the Slipstream Engine when a scan result is available. This asynchronous callback is not in sync with the screen update logic, therefore, manipulating the session e.g. setting the value of a text field will not directly update the screen but will only happen on the next regular screen update. To make sure that the scan results are shown correctly, we recommend to store them in the local session variable with session.put and then execute a different script that reads it from there and writes it into the text field. This call sequence synchronizes the asynchronous Cordova callbacks.
You are now ready to test the flavor using SAP Fiori Client application from your mobile device.