Skip to Content

Using Camera of mobile device in Screen Personas 3.0 SP 06

Jan 31 at 12:23 AM


avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Steve Rumsby
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);

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:
  • 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!

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi, i'm still have a problem with the response of the scanner method, the value is just updated on the screen after some event like a field enter for exemple. Any idea to solve this issue?

Thank you!


Using "executeScript" to update the field values, rather than a simple assignment, is meant to work around this problem. As I said above, "executeScript" should force a screen refresh. There's more detail now in this wiki page:


Former Member

I did that:

function scanSuccessCallback(result) {

	if (!result.cancelled) {
		var barcode = result.text;
		session.utils.log("scanned value: " + barcode);
		session.utils.put("scanvalue", barcode);

	} else {

function scanErrorCallback(error) {

	session.utils.alert("Scann Failed");

var cordova = window.parent.cordova;
if (cordova) {
	cordova.plugins.barcodeScanner.scan(scanSuccessCallback, scanErrorCallback);
} else {
	session.utils.alert("API not working!");

Where is my mistake?


Assuming your second script, the one called from executeScript, is similar to mine above, then I don't see anything obviously wrong, sorry. This might need an expert eye from one of the SAP guys - Tamas Hoznek, perhaps?


Former Member

Thanks Steve, I will try another solution!