cancel
Showing results for 
Search instead for 
Did you mean: 

Barcode scanner without pressing Scan Button

surya_jangareddy
Explorer
0 Kudos

Hi All,

Iam using Barcode scanner in my fiori app. Every thing is working fine....

But my client requirement is once he finish the scan, then immediately again another scan should be opened with out pressing button.

I done this requirement by using firePress event.But i am getting an issue like below.

First time when i press button and cancel, then from next time only its working as per requirement

So, how can i achieve it from first press onwards..

Thanks in advance,

Surya..

rakesh2901
Participant
0 Kudos

How are you calling the second scan??

gregorw
Active Contributor
0 Kudos

Does the cancel fire the scanFail event?

surya_jangareddy
Explorer
0 Kudos

sap.ndc.BarcodeScanner.closeScanDialog();

sap.ui.getCore().byId("barc").getAggregation("_btn").firePress();

Accepted Solutions (0)

Answers (1)

Answers (1)

surya_jangareddy
Explorer
0 Kudos

Hi,

First thanks to rakesh and Gregor for your response.

You can find my code below.

In View:

var oScanButton = new sap.ndc.BarcodeScannerButton({id: "barc",
provideFallback: true,
visible: true,
scanSuccess: onScanSuccess,
scanFail: onScanError,
inputLiveUpdate: onScanLiveupdate
});

now in function onScanSuccess.

function onScanSuccess(oEvent)

{
if (oEvent.getParameter("cancelled"))
{
sap.m.MessageToast.show("Scan cancelled", { duration:1000 });
}
else

{
aData.push({Sname: oEvent.getParameter("text")}); // Push data to Model
oModel.setData({modelData: aData}); // Set Model

sap.ndc.BarcodeScanner.closeScanDialog();

sap.ui.getCore().byId("barc").getAggregation("_btn").firePress();
}

}

this code is working fine like below.

1. when i press scan button ,

come back and cancel dialog.

now again press scan button . then only the repeated scan is working fine with out pressing scan button next time onwards.

otherwise i am getting an message like "barcode scan is already started."

Please help me.

Regards,

Surya.

rakesh2901
Participant
0 Kudos

Hi Surya,

As much as I understood your requirement, I think you should not fire the button again

sap.ui.getCore().byId("barc").getAggregation("_btn").firePress();/// remove this

instead call the:

sap.ndc.BarcodeScanner.scan

directly after first successful scan.

Hope I understood your requirement correctly. Let me know if it worked.

surya_jangareddy
Explorer
0 Kudos

Hi Rakesh,

Initially i have written the code as you suggested.But its not triggering Scan second time without pressing button.