cancel
Showing results for 
Search instead for 
Did you mean: 

Using Camera of mobile device in Screen Personas 3.0 SP 06

prasad_nekkanti
Discoverer

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

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!

Former Member
0 Kudos

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!

Former Member
0 Kudos

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: https://wiki.scn.sap.com/wiki/display/Img/Scripting%3A+Building+flavors+with+Barcode+scanning+functi...

Steve.

Former Member
0 Kudos

I did that:

function scanSuccessCallback(result) {

	if (!result.cancelled) {
		var barcode = result.text;
		session.utils.log("scanned value: " + barcode);
		session.utils.put("scanvalue", barcode);
		session.utils.executeScript("wnd[0]/scrptPersonas_080027E59F2C1ED8859A87D40EF060EE");

	} else {
		session.utils.alert("Cancelled!");
	}
}

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!");
}
<br>

Where is my mistake?

Former Member
0 Kudos

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?

Steve.

Former Member
0 Kudos

Thanks Steve, I will try another solution!

Felipe.

Guru
Participant
0 Kudos

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

Answers (1)

Answers (1)

deborah_chen2
Explorer
0 Kudos

Hi,

I tried Steve's script, but got "No scanner found". I will appreciate anyone to share the solution. @Guru, did you get any solution to share? Deborah