Skip to Content
0

sap.ndc.BarcodeScanner can not fetch camera of pad

Dec 22, 2016 at 02:57 AM

73

avatar image

Hello All,

I am trying to implement bar code scanner using standard sap library "sap.ndc.BarcodeScanner".

But i am not able to fetch camera and scan it. Instead only Input Field is displaying.

Can anyone Please help me regarding this?

10 |10000 characters needed characters left characters exceeded

Hi Edward,

Please provide the code which is not working.

0
Kedar Nath Tingrikar

Hi Kedar,

Thanks for you response!

My code:

onscan.txt

the button of scan in view.xml and the function onScan in controller.js

<Button type="Accept" text="{i18n>scan}" press="onScan" icon="sap-icon://bar-code" id="scanBtn" enabled="true" />

onScan: function(){
				flag = false;
				var that = this;
				var oData = this.getView().getModel('data');
				var oI18n = this.getView().getModel("i18n").getResourceBundle();
				//if (sap.ui.Device.os.android) {
					jQuery.sap.require("sap.ndc.BarcodeScanner");
					sap.ndc.BarcodeScanner.scan(
					   function (sResult) {
						   if (sResult.cancelled == false) {
							   var result = sResult.text.split(',');
							   if (result.length != 6) {
								   that.onScanError();
								   that.fShowMessageBox('error', oI18n.getText("codeError") + sResult.text);
								   return;
							   }
							   oData.setProperty("/materialNumber", result[0]);
							   oData.setProperty("/quantity", result[2]);
							   oData.setProperty("/batch", result[5]);
							   //set filter array
							   var aFilter = [];
							   //set material number filter
							   aFilter[0] = new sap.ui.model.Filter({
								   path: "materialNumber",
								   operator: sap.ui.model.FilterOperator.EQ,
								   value1: oData.getProperty("/materialNumber"),
								   value2: ""
							   });
							   //set login language
							   aFilter[1] = new sap.ui.model.Filter({
								   path: "language",
								   operator: sap.ui.model.FilterOperator.EQ,
								   value1: oData.getProperty("/language"),
								   value2: ""
							   });
							   //set plant
							   aFilter[2] = new sap.ui.model.Filter({
								   path: "plant",
								   operator: sap.ui.model.FilterOperator.EQ,
								   value1: defaultData.plant,
								   value2: ""
							   });
							   //get material description and unit
								oModel.read("/EntitySets/", {
									filters: aFilter,
									success: function(oERP, oResponse) {
										//check result: success
										if (oERP.results[0].msgty == 'S') {
											//set model
											oData.setProperty("/materialDesc", oERP.results[0].materialDesc);
											oData.setProperty("/unit", oERP.results[0].unit);
											flag = true;
											that.getView().byId('quantityid').focus();
											if (oERP.results[0].batchFlag == 'X') {
												that.getView().byId('batchid').setEnabled(true);
											} else if (oERP.results[0].batchFlag == '') {
												that.getView().byId('batchid').setEnabled(false);
												that.getView().byId('batchid').setValue("");
												that.getView().byId('batchlabelid').setRequired(false);
											}
										//check result: error
										} else {
											//error message output
											that.onScanError();
											that.fShowMessageBox('error', oERP.results[0].msg);
										}
									},
									error: function(oError) {
										//error message output
										that.onScanError();
										that.fShowMessageBox('error', oError.message);
									}
								});
						   }else{
							   that.onScanError();
							   that.fShowMessageBox('error', oI18n.getText("scanCancel"));
						   }
					   },
					   function (Error) {
						   that.onScanError();
						   that.fShowMessageBox('error', Error);
						   return;
					   },
					   function (mParams) {
					      alert("Value entered: " + mParams.newValue);
					   }
					);
				}else{
					that.onScanError();
					that.fShowMessageBox('error', oI18n.getText("scanError"));
				}
			}

onscan.txt (3.1 kB)
0
* Please Login or Register to Answer, Follow or Comment.

0 Answers