Skip to Content
avatar image
Former Member

Using Camera of mobile device in Screen Personas 3.0 SP 06

I am really excited about the SlipStream engine in SP 06 and understand native device features of mobile devices can be utilized. I am trying to figure out how to use the native device camera to scan a barcode. Would really appreciate if someone could give some insights on how this can be achieved using Screen Personas 3.0 SP 06...

Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 06 at 01:03 PM

    For this to work you need to run your slipstream flavours in the Fiori Client app rather than the device browser. This gives you access to the camera and other local devices. Once you are running in the Fiori Client, accessing the camera is fairly straightforward. The code looks like this:

    function scanSuccess(result) {
    	var matnr = result.text;
    	session.utils.log("Scan succeeeded: " + matnr);
    	
    	// Small hack to force a screen refresh after a field update
    	// in this asynchronous callback function
    	session.utils.put("message", matnr);
    	session.utils.executeScript("wnd[0]/scrptPersonas_005056840F9E1ED7BDAC77341716A0F9");
    }
    
    function scanError(error) {
    	session.utils.alert("Scan failed");
    }
    
    if(typeof cordova != "undefined") {
    	cordova.plugins.barcodeScanner.scan(scanSuccess, scanError);
    } else {
    	session.findById("wnd[0]/usr/txtPersonas_151368242701275").text = "No scanner found";
    }
    

    Some things to note:

    • The cordova scan function takes two callback functions, one if the scan is successful, one if it isn't. The above code doesn't do much if the scan fails!
    • These callback functions are called asynchronously, and so the usual Personas method of assigning values to a screen field's .text value doesn't work. There's no screen refresh to make the new value visible. That's what the "executeScript" is all about. That forces a screen refresh. So I "put" the scanned value, and do the screen field update in the called script, which obviously uses "get", like this:
    var matnr = session.utils.get("message");
    session.findById("wnd[0]/usr/txtPersonas_151368242701275").text = matnr;
    
    • More details of how to access the camera and other devices using the cordova API can be found here: https://cordova.apache.org/docs/en/2.4.0/
    • The "typeof cordova" test is trying to detect whether or not the script is running in the Fiori Client, and failing gracefully if not.

    Hope this helps!

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      I am running the SAP Screen Personas 3.0 SP07 flavor as a tile in FIORI launchpad using slipstream engine on SAP FIORI client app on iOS device.

      Everything works well except for scanning the bar code, I used the code as mentioned in your post, however I end up in "No scanner found", i am not sure why is it not finding the cordova plugins, I have downloaded the recent FIORI client app from the app store.

      Any advice, is the sample code you have put in does it work or need any tweaks ?

      With Kind Regards

      Guru